Page 1 of 1
Newb with OOP, Question concerning it.
Posted: Wed Oct 04, 2006 7:44 am
by akimm
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.
Posted: Wed Oct 04, 2006 9:19 am
by Jenk
OOP is not restricted to PHP
You will get a solid "Yes" from just about everyone on this board - learn OOP practices, and use them.
Posted: Wed Oct 04, 2006 9:31 am
by Maugrim_The_Reaper
The general OOP concepts are common to a large number of languages including Java and C++.
That would be a definite YES!

Posted: Wed Oct 04, 2006 11:08 am
by Luke
I'm 100% supportive of anybody learning OOP, but akimm, I'd suggest you master the basics first. Get used to writing logical code before you try to dive any deeper.
Posted: Wed Oct 04, 2006 2:39 pm
by jajumbo
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..
Posted: Wed Oct 04, 2006 2:44 pm
by Luke
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.
Posted: Thu Oct 05, 2006 9:53 am
by jajumbo
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.
Oh there are many out there like that.
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.

Posted: Thu Oct 05, 2006 10:06 am
by Jenk
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()
{}
}
Re: Newb with OOP, Question concerning it.
Posted: Thu Oct 05, 2006 11:27 am
by Christopher
akimm wrote:I just worry, for my redundant tasks, that OOP is sort-of overdoing 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.
Posted: Sat Oct 07, 2006 4:06 pm
by hrubos
I think you should learn OPP in Java or C++
Posted: Sat Oct 07, 2006 5:40 pm
by RobertGonzalez
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.
Posted: Sat Oct 07, 2006 9:32 pm
by s.dot
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.
Posted: Sat Oct 07, 2006 9:51 pm
by alvinphp
I personally say you go straight to OOP. Too often it seems people go to procedural and then never get out mainly because it is working so why change. OOP will not only be beneficial for PHP, but for many other languages.