Hudzilla.org - the homepage of Paul Hudson
Contents > Wish List | Report Bug | About Me ]

6     Objects

This is NOT the latest copy of this book; click here for the latest version.

The object-oriented programming (OOP) paradigm has been around for many years now, although the degree to which it is support varies widely across languages. C++, for example, is object-oriented C, and, as some purists would say, implements more OOP functionality than even Java does.

Before PHP 5 came along, OOP support in PHP was quite flaky and more of a hack than a serious attempt. As a result the few that used it often regretted the choice, and it is not surprising that the whole system got a full rewrite in PHP 5 - it is now much more advanced and flexible, and should please just about everyone.

Topics covered in this chapter are:

  • Objects and classes defined

  • Class inheritance

  • Access control

  • Runtime type information

  • Abstract and final properties and functions

  • Constructors and destructors

  • Magic functions

Author's Note: If you have used OOP in PHP 4, I strongly recommend you read this entire chapter from start to finish - OOP has been massively redesigned in PHP 5, and is much more functional and feature-rich now.


Chapter contents

6.1. Conceptual overview
6.2. Classes
6.2.1. Defining a class
6.2.2. How to design your class
6.2.3. Basic inheritance
6.2.4. Overriding functions
6.3. Objects
6.4. Variables
6.5. The 'this' variable
6.6. Objects within objects
6.7. Access control modifiers
6.7.1. Public
6.7.2. Private
6.7.3. Protected
6.7.4. Final
6.7.5. Abstract
6.7.6. Iterating through object variables
6.8. Object type information: instanceof and is_subclass_of()
6.9. Class type hints
6.10. Constructors and destructors
6.10.1. Parent constructors
6.10.2. Destructors
6.10.3. Deleting objects
6.11. Copying objects
6.12. Comparing objects with == and ===
6.13. Saving objects: __sleep(), __wakeup(), and get_object_vars()
6.14. Magic functions
6.14.1. __autoload()
6.14.2. __get()
6.14.3. __set()
6.14.4. __call()
6.14.5. __toString()
6.15. Static data
6.16. Helpful utility functions: class_exists(), get_class(), and get_declared_classes()
6.17. Interfaces: get_declared_interfaces()
6.18. Deferencing object return values
6.19. The Object-Oriented Website
6.19.1. A basic OOP site
6.19.2. A more complex OOP website
6.20. Summary
6.21. Exercises
6.22. Further reading
6.23. Next chapter



<< 5.15 Next chapter   6.1 Conceptual overview >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
A PHP User - 04 Jul 2008

hi thetre.. this is really cool :) ?> <?php jhsadfjk;hadfjhadf?>

A PHP User - 04 Jul 2008

it is fuckin hooooooooooooooooooooooottttttttt

A PHP User - 04 Jul 2008

it is sexy

A PHP User - 04 Jul 2008

This is f.... excellent..!! I really do understand now..

Thanks..:-)

A PHP User - 04 Jul 2008

Should I just skip this if I will be using php4?

LocalHost - 04 Jul 2008

You can always run a local web server, which is what i recommend.

A PHP abUser - 04 Jul 2008

ignore the comment below, ive found out my hosts do support PHP5, you just need to save the file with the extension .php5 or alternatively write a short config file in the main directory.

A PHP User - 04 Jul 2008

This may be a bit of a problem because my Web Hosts only have PHP 4 installed and not PHP 5. Theyre one of the biggest around too (1&1).

I'll read through the chapter and see if i can draw any relevance from it....(hopefully!)

A PHP User - 04 Jul 2008

WoW, excellent job man. Thank you for keeping this execellent notes for free. I wish you all the best.

Is there anyway i can printout the whole sites or notes ?

Regards



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is five plus five?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow