PHP OOP ???
Moderator: General Moderators
PHP OOP ???
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!!
- Mastermind
- Forum Commoner
- Posts: 36
- Joined: Thu Mar 10, 2005 2:38 am
- Location: CDO,Philippines
- Contact:
-
Simulacrum
- Forum Newbie
- Posts: 13
- Joined: Wed Apr 13, 2005 11:58 pm
Re: PHP OOP ???
There's a couple of websites that might help you: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!!
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.
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:
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.
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);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.
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/
http://www.mindview.net/Books/TIJ/
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?Mastermind wrote:yes try to search in google.
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...
Pretty much, yes. Similar design issues and techniques like unit-testing apply to all languages.mudvein wrote:Mastermind wrote:Is OOP the same no matter the language?
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.
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
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