/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] What’s the difference between using objects and include’s?

Hi,

I have read a few tutorials about objects but I still don’t understand their utility in my own project.

However, I make extensive use of include files in my php script.

My question would be:

Can include files be considered as having the same advantages as object? What I mean is that, if I want to change something in my script, I can do so by changing it in one single place. So it seems just as convenient to me as objects.

What are you thoughts on that?

Thanks a lot

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@kristovaherFeb 21.2012 — By objects you mean classes?

They are entirely different concept compared to including files. They cannot be compared at all. A class is a self-contained 'program' of sorts that can be used during execution of other, larger, programs. It's contained within its own boundries.

An include is just a file full of code that is being included. That file can too be a class definition.

You need to learn a lot about object-oriented programming, web is full of tutorials so I suggest you start from there ?
Copy linkTweet thisAlerts:
@eric01authorFeb 21.2012 — Hi kristovaher,

Thanks for your response. I understand your point.

I will look more into practical examples of OOP to better understand their use.

Regards
Copy linkTweet thisAlerts:
@eval_BadCode_Feb 21.2012 — OOP is really a crutch for the programmer, the computer doesn't need OOP to run. :p


My classes are each contained in their own file, and some of them even include other files (templates) for rendering themselves as a string. So this question of include vs OOP makes little sense, although there are many similarities between the two, they are a world apart.


I think OOP is good for a few things, among them: solving a complex problem, reusing code, building a complex system. I would advise you to learn the basics of procedural programming first. No matter what type of programming style you end up using, it will build on the experience you gained from procedural programming (or however you decide to start). :p
Copy linkTweet thisAlerts:
@eric01authorFeb 21.2012 — Hi,

Yes, I am sticking to procedural programming for now, but I keep OOP in mind because ultimately, I want to acquire solid knowledge on programming.

Thanks again!

Regards
Copy linkTweet thisAlerts:
@aj_nscFeb 21.2012 — Most everybody begins learning programming techniques using procedural programming (unless you're working with a object-based language like Java) so there's no problem with it. Always keep OOP in your mind, though, because if you don't progress past procedural eventually, then you'll be missing out on an extremely powerful world of coding.
Copy linkTweet thisAlerts:
@George88Feb 21.2012 — Also a note on reusing code; yes, objects can offer this ability, but generic code is not necessarily object-oriented code. Writing reusable code is more to do with writing generic code. In other words, code that can be used with any type of data or information, such as sorting algorithms like qsort in C. PHP goes a long way to make code more generic by virtue of its loosly typed nature, but effort should still be made to make code reusable. One thing I enjoy doing is when I create a function or class that can be implemented with more than just the data I am currently working with, I add it to my own library file and think hard about how I can make it more reusable.

In my opinion classes in PHP are something that you won't use very often as opposed to other languages. Like others have said, they're not necessary in programming, but make certain things easier to code. If you've ever programmed in a general-purpose programming language like C or C++, then you'll realise that classes are just an extension of structures which also aren't really necessary but go a long way to helping you write encapsulated code. Interestingly, structures were created as a way of allowing programmers the ability to create custom-type variables (generic-type variables). Since PHP is loosly typed you may not even know what a data type is, so your whole understanding of classes & objects is probably distorted from the beginning.

Remember that structures were created to allow custom-type variables to be made by programmers in an effort to create generic code, and classes were created as a way of extending structures to allow more complex operations to be performed on the members of the construct. For example, C++ added the ability to create member functions, which are functions that are bound to their parent class and only accessible from there. C++ also added the ability for classes to overload operators and write more powerful and accessible code.

In my opinion if you're going to understand classes and objects in full, then it would be wise to learn the language in which they were created (C++ (might be wrong about this point)). You will probably never take full advantage of object-oriented programming with PHP alone, but of course that may not even be your goal.

Anyway, once you have begun learning the basics of OOP you'll see it isn't nearly as scary as it first seems. For many people it is a natural coding style and makes more sense, but for others it isn't so intuitive.
Copy linkTweet thisAlerts:
@eric01authorFeb 21.2012 — Thanks everyone for your useful info. I read it carefully and really appreciate your help!

Regards
×

Success!

Help @eric01 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...