40 Comments
- wonderbud, on 10/12/2007, -0/+10OOP is really cool.
Once you start you just cant stop.
(just like pringles)
*edit*
This tutorial really isnt very complete or good. I would look for a new one. - imjustabill, on 10/12/2007, -1/+8I would hope that anyone who calls themself a programmer has worked with classes before.
- MannaPC, on 10/12/2007, -1/+7For the love of mike! Stop posting crappy PHP-Editor articles!!!!!!!
- geminitojanus, on 10/12/2007, -0/+6In the industry, for a very long time, PHP was referred to as Scriptable C. It was never meant to be Perl; Perl was OO from ages ago, and is a world-class OO language of its own. PHP was a drop-in replacement to [[Language]]/CGI (common gateway interface), ergo C. PHP's object oriented nature is only now being given any thought, now that it is mature enough to use. Anyone who's writing PHP4 code with object orientation is writing the C equiv of a C++ application (which, as impossible as it does sound, is not quite as bad as it sounds; C++ was actually implemented as a higher abstraction of C (C++->C->Machine Code) before it was given its own native compiler).
Believe it or not, I use PHP as a drop-in replacement for Perl in shell scripting, simply because I don't like a lot of Perl's eccentricities (and because I'm a very, very long time C programmer, I can't handle Python's formatting and rather profuse use of OO, and the fact that it's slower than grandmother's molasses in the dead of winter when doing anything complex with objects [if you don't believe me, run Bittorrent/Python vs Transmission or uTorrent (Azureus is Java, even with JIT, it's slow as ass)]). - halikar, on 10/12/2007, -1/+6If you are looking to get an understanding of OOP, this is great. If you are looking for the philosophy behind OOP and textbook learning, then I'd agree droppedd. But, since that's not what this is stated as being, he bonlebon gets my digg and you don't.
- craigtheguru, on 10/12/2007, -0/+4I agree. If you came to me wanting a job and you didn't know OOP, you wouldn't get very far nor would be able to answer our technical questions, let alone understand them.
- seanmc303, on 10/12/2007, -1/+5I agree with droppedd. I'd even take it a step further to say that this is a very bad tutorial. If you are just learning how to do object oriented programming in PHP, you had better be starting in PHP5 which is can be fully object oriented instead of pseudo OOP PHP4 crap. This is an example for PHP4 and if you are using PHP5 DO NOT READ THIS TUTORIAL if you don't want to have to relearn how to do things the right way. This tutorial will only lead to bad coding practices.
- geminitojanus, on 10/12/2007, -0/+4Encapulation is only 1/3rd of the triad of advantages Object Oriented Programming has.
Quick recap of Computer Science 102: Encapsulation is Objected Orientation goal #1; wrap the data with the methodologies of accessing and using that data. Code Reuse is goal #2; code objects, once created, are virtually endlessly reusable if generic enough (See OS X/Cocoa if you need any example). Lastly, polymorphism and code genetics is goal #3; in any object oriented language, objects can be extended to allow for a greater amount of encapsulation, and a larger amount of reuse. Some people disagree on adding more fundamental points of OOP, but generally, everyone agrees on these 3 at least. - jarod42, on 10/12/2007, -1/+5I want someone to write an OOP tutorial without using cars, keys/locks, or some other silly example...
:) - jo42, on 10/12/2007, -0/+3PHP Object Oriented Programming => POOP
- xst4t1kx, on 10/12/2007, -1/+4Numerous errors throughout the article.
- marnaq, on 10/12/2007, -3/+5Yes, yes. This is technology breaking news.
- fitzy, on 10/12/2007, -0/+2Ya this tutorial really isn't that good for php classes....
- cbeach, on 10/12/2007, -0/+2The example code doesn't use a constructor, which is a serious omission. Also, PHP object methods should not use "echo" statements. Doing so reduces their reusability - instead they should have a getHTML() method, or similar, and pass out any output through this.
- DennisP, on 10/12/2007, -0/+2This isn't an tutorial on OOP, it's a tutorial on using classes. OOP is a whole different way of programming, and it can be quite challenging to make the switch from procedural.
I haven't got any links real OOP tutorials though, but I can highly recommend SitePoint's PHP Application Design (http://www.sitepoint.com/forums/forumdisplay.php?f=147) forum if you want learn more about OOP and design patterns in PHP. - jackrabbit, on 10/12/2007, -0/+1This is a pretty lousy explanation, uses poor wording and bad examples. If you don't know objects and classes already, this tutorial will be of little help. Undigg.
- manicarzo, on 10/12/2007, -2/+3Yeah, I don't yet know OOP. Hopefully reading this will help out?
- inactive, on 10/12/2007, -0/+1Hi CHEMiST, at the top it said that the user required PHP4 but I did feel it should be more strongly worded as being PHP4 only.
That and there are some very bad coding standards being displayed and getting these right wouldn't have hurt the example at all. Inspires me to do a rewrite someday :) - adolfojp, on 10/12/2007, -0/+1Then I recommend that you look for a tutorial on any ORM model :-).
- bitt3n, on 10/12/2007, -0/+1what are some examples of good books/tutorials for OOP newbs?
- Pizpump, on 10/12/2007, -0/+1"If you only want ot focus on OOP, try C ; not Java (lack of inheritance)." - hufnmouth
Wrong. Java has single parent inheritance. Wouldn't be OOP if it didn't... - bigkm, on 10/12/2007, -0/+1this book would help more especially with php 5.
http://www.amazon.com/gp/product/1590593804/102-8182694-1146544?v=glance&n=283155
i bought it a few months ago and it has been well worth it. simple explainations and understandable situations where oop is very practical. - Majdaa, on 10/12/2007, -0/+1I'd strongly recommend "Design patterns: Elements of Reusable Object-Oriented Software" to anyone taking OOP seriously...it's a classic
http://www.amazon.com/gp/product/0201633612/sr=8-1/qid=1144099678/ref=pd_bbs_1/002-8306082-7388067?%5Fencoding=UTF8 - macboy, on 10/12/2007, -0/+1it only skims the surface in a very superficial way. It's far from the best tutorial out there, a quick google search might yield better results for anyone looking to delve into OOPHP (which is the best thing since sliced bread).
- spectre_25gt, on 10/12/2007, -0/+1Here's another link that might be useful: http://sepwww.stanford.edu/sep/josman/oop/oop1.htm
- hufnmouth, on 10/12/2007, -1/+1This tutorial will whet your appetite for classes, but that's about all. Start with OODesign/OOAnalysis which will help make OOP a lot less daunting. If you only want ot focus on OOP, try C++; not Java (lack of inheritance).
- funpet, on 10/12/2007, -0/+0I can't say I've stopped using OOP since I learned it years ago, but I've definitely used it a LOT LESS in the past year.
- etx313, on 10/12/2007, -1/+1OOP FTW!
- adolfojp, on 10/12/2007, -1/+1It makes me sad that PHP fans will mod you down even if you are telling the truth.
- stinkyj, on 10/12/2007, -2/+2OOP is about encapsulation, not syntax. knowing how to say the words is useless if you don't know what they mean. if i hadn't just woke up i would look for a better tutorial.
- CHEMiST, on 10/12/2007, -0/+0First thing I noticed in the article was how instance variables were declared using var instead of private/public/protected. Teaching new users to declare instance variables with var creates confusion in the long run. If you are new to PHP and are interested in taking advantage of OO then make sure to stick with the PHP5 conventions. If you are new to OOP entirely it might be worth your while to dig into an intro to Java or C# book, both of these languages are very clean and based on true OO paradigms. Hope this helps someone... ;-)
- mhakes, on 10/12/2007, -0/+0It misses much of the richness of php's object oriented features! Look for a better one!
- gewthen, on 10/12/2007, -0/+0Only talks about PHP 4 and later. PHP5 have much more for object oriented programing.
- hijinks, on 10/12/2007, -2/+1php is not a good language to learn OOP from.. 5 is a step in the right direction but not even close.
This is soo basic its a worthless read.. it goes over OOP thats been in php since i learned it in the early 4 days when it was just a starting point. If you want to learn OOP in php find a good php5 OOP article. - fitzy, on 10/12/2007, -4/+3Really if you want to learn OOP, learn java...
- sontek, on 10/12/2007, -1/+0This is a very nice starter tutorial but really doesn't give you any real experience on developing object oriented code in PHP. I dugg it just because I think some people will get use out of it.
- lsinger, on 10/12/2007, -4/+3"The trouble comes from the fact that not all programmers have worked with Object-Oriented Programming (OOP) before."
The real trouble comes from the fact that PHP is just a borked language, especially when it comes to writing object oriented applications using the obsolete-but-still-widely-used PHP4 with it's counter-intuitive object-handling. - DroppedD, on 10/12/2007, -5/+3this is fairly useless. as a very, very basic OOP introduction i guess it works, but if that's what they were going for they should've talked a little more about the philosophy behind OOP. there are much better tutorials and books on OOP even in PHP that start off just as easily, but actually build up into something useful.
- generalbob, on 10/12/2007, -4/+1nice tuts
- stinkyj, on 10/12/2007, -5/+1i agree. PHP is not the language to learn OOP with. for a far better example, try c , python, or ruby.


What is Digg?
Digg is coming to a city (and computer) near you! Check out all the details on our