PHP OOP ???

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
mudvein
Forum Commoner
Posts: 45
Joined: Wed Mar 16, 2005 4:39 pm

PHP OOP ???

Post 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!!
User avatar
Mastermind
Forum Commoner
Posts: 36
Joined: Thu Mar 10, 2005 2:38 am
Location: CDO,Philippines
Contact:

Post by Mastermind »

yes try to search in google.
Simulacrum
Forum Newbie
Posts: 13
Joined: Wed Apr 13, 2005 11:58 pm

Re: PHP OOP ???

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Last edited by McGruff on Sat Aug 06, 2005 12:23 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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/
mudvein
Forum Commoner
Posts: 45
Joined: Wed Mar 16, 2005 4:39 pm

Post 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...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 :)
Post Reply