Classes and Objects in PHP
August 1, 2007
I’ve written up a short (2 pages,) document that goes over some of the very basics of object oriented programming – it should take you all of 5 minutes to read.
I wrote this as the preamble to my next video on object oriented PHP where we will actually create living breathing PHP objects.
Here’s a small snippet from the PDF:
How objects are created:
You create a class that ‘describes’ an object. Much in the same way a blueprint ‘describes’ a building. Instead of room dimensions etc … PHP classes / blueprints details a bunch of things about an object:
a. Variables it contains.
b. Functions it contains – yep, classes typically have functions in them.
Objects are much more powerful and complex when compared to functions. As such, there are many other special things that can be found in classes, which are unique to classes. Again, more on that later.
Once you’ve defined your class, you are ready to tell the PHP engine to actually create a class from your blueprint. There are special commands (PHP code,) that tell the PHP engine to create an object from the ‘blueprint’ you described/outlined in a class.
When the PHP script is run (with the code that instructs PHP to create an object … based on the class,) PHP actually creates a living, breathing object based on your class.
What I mean by ‘creates a living, breathing object, is to mean that the object is actually created in (server) memory.
Thanks for reading and watching.