Classes and Objects in PHP

August 1, 2007

php logo

Hi,

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:

Step 1:

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.

Step 2:

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.

Step 3:

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.

Stefan Mischook

www.killerphp.com
www.killersites.com

4 Responses

  1. Pingback: PHPDeveloper.org

  2. Pingback: developercast.com » Stefan Mischook’s Blog: Classes and Objects in PHP

  3. hkarthi Author August 12, 2007 at 4:40 am

    hi

    i am really impressed with your work. i would like to know if you could come up with some kind of tutorial/video, which would help newbies like us on how to build a website using php from scratch? part by part would be nice… thanks to your website and your article, i have already know a bit of php programming and would help me and others like me to understand more about php and develop some cool sites. Thanks!

    karthi 🙂

  4. Stefan Mischook Author August 12, 2007 at 10:28 am

    hkarthi,

    Thanks for the positive remarks and I appreciate your suggestion – I will consider it.

    I will be putting out many more PHP videos in the near future.

    Stefan

To Top