Tutorials

OO PHP Part 1: OOP in Full Effect

by John Kleijn on Jun 6, 2008 3:21:29 PM

Introduction

On the old site, I started a series of tutorials named "PHP Application Design". I planned for at least three parts, and while I did publish the first two and wrote at least half of part three, I found myself out of time to make it to the finish.

Still dedicated to writing reusable and extensible PHP code and spreading the knowledge, this is a restart of the series, renamed as simply "OO PHP". So:

Welcome to part one of the "OO PHP" series.

This article is an overview of what PHP has to offer with respect to OOP, with examples on how to use these concepts.

If you have wanted to grasp OOP, but haven't come around to learning it, this article is for you. If you've read some "Hello World" in OOP tutorial, gotten familiar with OOP syntax but are interested in learning more, this article is for you too.

A couple of things have changed in this tutorial. First off, PHP 4 examples and references have been stripped. PHP 4 is dead, let’s look to the future. In that same frame of mind, this tutorial now has some brief coverage of namespaces and late static binding, introduced in PHP 5.3. Finally, the last chapter from the original has been stripped, or rather moved to a future part of the series.

Index

1. The Very Basics
1.1 A tiny bit of theory
1.2 Hold on, read this disclaimer first
1.3 Absolute basic syntax
2 Defining how objects should behave
2.1 Classes
2.2 Inheritance
2.3 Constructors
2.4 Scope Resolution Operator
2.5 Abstract Classes
3 Beyond the Absolute Basics
3.1 Object Handles
3.2 Interfaces
3.3 Autoload
3.4 Destructors
3.5 Visibility
3.6 Class Constants
3.7 Type Hinting
3.8 Exceptions
3.9 The Final Keyword
3.10 More Magic Methods
3.10.1 Object Overloading
3.10.2 Object cloning
3.10.3 Serialization
3.10.4 Other
3.11 Object Iteration
4. Hot off The Press Features
4.1 Namespaces
4.2 Late static binding
In conclusion

Comments

Looks like a nice intro loaded with information. Some things I see lacking in OOP with PHP is the use of get and set methods. When learning OOP in java this was a key thing we learned I just think it makes good practice.

1. Jeff Combs on Jun 6, 2008 8:17:36 PM

I agree wholeheartedly, but as it says in section 1.2: this tutorial only shows the language features.

Good practice will be a subject soon enough.

2. John Kleijn on Jun 7, 2008 3:43:41 AM

I can't wait for the rest of the series, I've been struggling to learn good OOP Application design for some time because I don't have any peers where I work who know the subject, given this first part I think I will learn a lot and really appreciate the author's efforts. Thank you!

3. phpzone on Jun 7, 2008 8:51:58 AM

You're welcome (though I can never have enough of gratitude). ;)

Note that part 2 is already online, and part 3 underway.

4. John Kleijn on Jun 7, 2008 11:51:03 AM

lovin this. :D

5. aim25 on Jun 22, 2008 11:46:05 AM

Cool tutorial, really useful and easy to understand

6. Jack Bert-Oswald on Jul 15, 2008 11:04:27 PM

Thanks man, really helpful. Tutorial is great but i think that would be great to add some more explaining on interface if you have time cauz i really didn't understand what should i do with the code you give as an example. Thanks for effort to make this tutorial.

7. HardCoreMore on Jul 18, 2008 2:44:31 AM

From 2003 I am great follower of php tutorials by phpfreaks. It's very useful the stuff on advanced. These kind of tutorials make us strong in fundamentals.

Good work.
sharma chelluri

8. sharma chelluri on Aug 1, 2008 8:52:31 AM

Great tutorial, but honestly, we're not programming PHP animals. In future tutorials, could you cut the crap about the dog and provide code that does something meaningful?

9. sneamia on Sep 13, 2008 5:12:13 PM

As a beginner I like analogies that make it easy to follow.

10. arwvisions on Oct 4, 2008 11:16:59 PM
Login or register to post a comment.