Archive - Originally posted on "The Horse's Mouth" - 2009-05-11 05:47:18 - Graham Ellis
In PHP, there was a major change in the object model between version 4 and version 5. This code here - incredibly - runs differently on the two versions and what happens when you assign an object to another variable has changed.
In PHP 4, the object being assigned is duplicated, so that if you change the original object after doing the assignment, then look up a property in the copy, you'll be given the value that you started with
In PHP 5, the new variable is just an extra name (an alias, if you like) for the original variable, so that if you change the original object after doing the assignment, in reality you're changing both. So that when you look up a property in the copy, you'll be given the value that you have just set in the original
This (and other entries this morning) are taken from the board examples I wrote during last Friday's Object Oriented Programming in PHP course. Each day during training, I'll draw dozens of diagrams to help delegates understand what's going on, and when asked I'm happy to document and publish some of them here. Bookings on our public courses are open - in other words, we'll accept bookings and welcome delegates who want to learn what we teach from any company or organisation, contractors, and private individuals. The prerequisites?
• A desire to learn
• A good understanding of the language in which the course is presented
• For advanced courses - enough technical background / prior knowledge to be able to gain from the course (and to not hold up other delegates)
There's a full list of our public courses for the rest of the year at http://www.wellho.net/course/index.html - we have beginner and advanced course in PHP ... and also Linux, Java, Perl, Python, MySQL, Lua, C, Tcl, C++ and Ruby.