Page 1 of 1

PHP OOP ???

Posted: Fri May 27, 2005 8:52 pm
by mudvein
Hello. I have been learning OOP and there is still a lot I do not understand. Like how references work, or object comparison. So here is my question: Is there a book for PHP that mainly just covers OOP both intermediate and advanced?? If so, please let me know!!

Posted: Sat May 28, 2005 1:50 am
by Mastermind
yes try to search in google.

Re: PHP OOP ???

Posted: Sat May 28, 2005 7:58 am
by Simulacrum
mudvein wrote:Hello. I have been learning OOP and there is still a lot I do not understand. Like how references work, or object comparison. So here is my question: Is there a book for PHP that mainly just covers OOP both intermediate and advanced?? If so, please let me know!!
There's a couple of websites that might help you:

http://www.phpclasses.org/ This site has a lot of classes that are added daily
http://www.phppatterns.com Nice explanations of how you can use design patterns in PHP

Bookwise, the only PHP book I've read was PHP5 and MySQL by Jason Gilmore, which I thought was pretty good. But there is also a book called PHP 5 objects, patterns and practice that should help

Other than that, I'd recommend Code Complete 2 as being the best overall coding book available.

Posted: Sat May 28, 2005 9:23 am
by McGruff
One of the best intermediate/advanced books on OOP is Martin Fowler's Patterns of Enterprise Application Architecture. You can see some pattern summaries here - but the book explains in more detail. It's an essential textbook for all programmers. Fowler is a god.

References work differently in php4 and php5. In php4, copies are made by default. Almost always you want a reference instead so:

Code: Select all

// assign by reference
$foo =& new Foo; 

// return a reference
function &newFoo() 
{
    return new Foo;
}

// pass by reference
function bar(&$foo)
{
}
// but you don't need to do this 
// (in fact it will trigger an error 
// depending on your error reporting settings):
$a = bar(&$foo);
There's actually a bug in php which affects object comparison. Not many people run into it and I don't think the php developers are taking it very seriously. See here.

The most important thing for you to learn is unit-testing. Amongst many benefits, it will almost eliminate lengthy debugging sessions making you much more productive. See link in my signature below for Marcus Baker's excellent SimpleTest. I couldn't work without it. It's the only one with mock objects afaik, and includes a nice little webtester which can even handle form submissions.

Posted: Sat May 28, 2005 11:50 am
by hawleyjr
One of the best OOP books I've read is "Thinking in JAVA" - Bruce Eckel. I bought the book. However, you can download a PDF version of the book here:

http://www.mindview.net/Books/TIJ/

Posted: Sat May 28, 2005 12:05 pm
by mudvein
Mastermind wrote:yes try to search in google.
you know, this kind of post is exactly what urks me and most anyone else that has a problem. If you can't come up with anything better than "Search Google", why post at all?

Anyways, thanks to everyone else who posted some good sites and books. I am definately going to look into viewing all the sites as as well buying all the books.

Here is my last question on this subject before I do :

Is OOP the same no matter the language? IOW: Do the functions work the same in C++ that they would in PHP? Just wondering because I couldn't help but notice the posting of different languages within this thread as I said PHP. So, does OOP in Javascript work the same with PHP? Thanks


edit : Also , i'm only going to be using PHP 4. I don't plan on using 5 for a while now. yes i know, php 5 has been updated and there are all kinds of great new features, but I'm only working with 4 at the moment and will eventually move to 5...

Posted: Sat May 28, 2005 12:58 pm
by McGruff
mudvein wrote:
Mastermind wrote:Is OOP the same no matter the language?
Pretty much, yes. Similar design issues and techniques like unit-testing apply to all languages.

One thing about php is that it's a scripting language. There's no state between requests so you wouldn't design things exactly the same as you would in java for example. Lazy-loading (just-in-time instantiation of objects) becomes more valuable since you don't want to do any more than you have to in a particular request.

I don't have any experience with other languages so it's not something I can say much about.

Posted: Sat May 28, 2005 1:12 pm
by timvw
I've had a java course once that placed focus on reuse, reuse and reuse :p
So they spend a lot of time to oop and patterns... A bit on refactoring.. Meaby they publish it some day ;)


If i'm not mistaken, the main subject in the course is "Carl the Robot". And you are asked to write some code to draw a face (which has eyes, mouth, nose, ..) And you can move him around.. But before you can do that, you learn how to a square, triangle etc... And then it's only a matter of making a "composition" of those to end up with a complete face.

After that you can make a Carla, his sister. She inherited the same genetical structures, but she "behaves" a little different...

Story should be more than good enough to demonstrate the power of OOP :)