Newb with OOP, Question concerning it.
Moderator: General Moderators
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
Newb with OOP, Question concerning it.
Hello all, I have been teaching myself php for a few months here, and in my quest to become proficient I have come across the question many times, should I learn the OOP of PHP. If anyone can give me some idea, pros and cons of it, what their preference is, et cetera.
Secondly, if php OOP is not worth learning what languages would be a suggested place to learn, because, I really like the way OOP works, for the little I know. I just worry, for my redundant tasks, that OOP is sort-of overdoing it.
Thanks all!
Sean.
Secondly, if php OOP is not worth learning what languages would be a suggested place to learn, because, I really like the way OOP works, for the little I know. I just worry, for my redundant tasks, that OOP is sort-of overdoing it.
Thanks all!
Sean.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
OOP is not as difficult as it sound, but it is not as easy as some people may lead you to think.
I would say, Yes to learn OOP, No to restrict it to PHP only.
A good starting point to learn OOP is simply Java.
Cpp, u don't want to go there, unless you want to start playing with ptr->ptr->ptr->ptr->ptr->
php, you can still do something like that, but it is not as difficult as Cpp or Java.
Also, if you want to really use and learn OOP,
I suggest php5.
because php4 does not support public/private tags..
I would say, Yes to learn OOP, No to restrict it to PHP only.
A good starting point to learn OOP is simply Java.
Cpp, u don't want to go there, unless you want to start playing with ptr->ptr->ptr->ptr->ptr->
php, you can still do something like that, but it is not as difficult as Cpp or Java.
Also, if you want to really use and learn OOP,
I suggest php5.
because php4 does not support public/private tags..
Oh there are many out there like that.The Ninja Space Goat wrote:yea I didn't understand or like OOP at all until PHP5 when PHP finally got it (for the most part) right. If OOP was, in other languages, how it is in PHP4, I doubt it would be so popular.
OOP has been around for a while... well first it wasn't fully OOP, but nowadays, atleast the very least you should be able to create private and public variables.
php 4's style of OOP, to me, is making life easy for php developers.
For example, if many coding languages, object's default internal variables are all private or protected.
of coz, then there are those that are automatically public.
php4 follows the later one but does not allow you to turn it into a private mode. Also it seems all functions written in PHP are public.
While in most OOP languages that I know, functions can also be public/protected/private... don't forget, virtual
PHP seems to be in between oop and Imperative.
that's why it was so easy to pick up for me.
To this date, I've only been using php for 2 months. but I have been coding in Java, C, Cpp, VB for awhile.
php5 saw the inclusion of public/private/protected keywords for use in class properties and methods.
Code: Select all
class Foo
{
private $bar;
public function fooBar()
{}
}- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Newb with OOP, Question concerning it.
I think for "redundant tasks" OOP should be a time saver for you. It is in the little one-off scripts where procedural PHP works well -- essentially where the entire script is a single class.akimm wrote:I just worry, for my redundant tasks, that OOP is sort-of overdoing it.
(#10850)
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
There are really no cons to OOP in PHP, especially with the way in which PHP5 handles OOP. I would suggest you wrap your mind around logical procedural code flow (not necessarily procedural coding, but the flow of the code) before you get too deep into OOP as you are going to want to be able to code cleanly and efficiently to really unleash the full power of OOP. That is not to say that bad code can't work in OOP, but to really use OOP in the manner that it is best suited to, you are going to want to make sure your code is clean.
I'm personally a procedural programmer. Although, I can code php4 style classes and use them in conjunction (right word?) with other objects.. thus being a certain degree of Object Oriented.
I'd say if you're not working in a group environment, do whatever makes you more comfortable. While learning OOP, code procedurally until you're comfortable enough to go all out.
I'd say if you're not working in a group environment, do whatever makes you more comfortable. While learning OOP, code procedurally until you're comfortable enough to go all out.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.