Wondering where to start? Check out our web designer, web programmer or small business road maps.

Archive for the ‘Object Oriented PHP’ Category

Building Objects in PHP – Part 3

Sunday, September 9th, 2007

PHP Video Tutorial

Hi,

I’ve just released part 3 of my videos on objects in PHP.

In this video, I clarify a point I was trying to make in part 2. In a nutshell, I talk about why it makes sense to keep any page rendering code (HTML and CSS) out of your business logic classes.

.. I cover the details in this video.

Thanks,

Stefan Mischook

www.killerphp.com

Building Objects in PHP – Part 2

Sunday, September 9th, 2007

PHP Video Tutorial

Hi,

I’ve released part 2 of the video: Building Objects in PHP

In this video, we actually use the object we created in Part 1, in our PHP page.

-

I will have another video to clarify and wrap things up covered in Part 1 and Part 2.

Thanks,

Stefan Mischook

New Video: Building Objects in PHP

Friday, September 7th, 2007

PHP Video Tutorial

Hi,

I just released part 1 of my video on building objects in PHP.

This is a hands-on video where I hope the viewer will actually write code along with me. I want to stress that this video (like everything else on this site,) targets beginners .. not old PHP hacks.

… My goal is to make object oriented programming approachable to everyone.

-

Part 2 should be out within a few days.

Thanks,

Stefan Mischook

www.killerphp.com

Why learn OOP in PHP – another take.

Friday, September 7th, 2007

php logo

Why learn OOP in PHP – another take.

For people new to OOP and are comfortable with ‘classic’ procedural php, you may be wondering why should you even bother to learn object oriented concepts … why go through the trouble?

The PHP world:

PHP is moving in an OOP direction. For example, many important PHP extensions like PEAR and Smarty are OO based. So, to really understand and use these frameworks properly, you need to understand object oriented PHP.

The functional/practical advantages:

For smaller projects, using object oriented PHP may be overkill. That said, object oriented PHP really begins to shine as the project becomes more complex, and when you have more than one person doing the programming.

For example:

If you find that you have say 10-20 or more functions and you find that some of the functions are doing similar things … it is time to consider packaging things up into objects and using OOP.

OOP and your career as a programmer:

OOP is the modern way of software development and all the major languages (Java, PERL, PHP, C#, Ruby) use this method of programming. As a software developer/programmer, it only makes sense (in terms of career,) to keep your skills up-to-date.

Besides making you a more valuable PHP coder, understanding OOP in PHP will give you knowledge (OOP knowledge,) that you will be able to take with you into other languages.

… When you learn OOP in PHP, you’ll learn object oriented programming for any OO based language.

You will find with time that creating OOP based PHP projects, will just make your life as a programmer much easier. As an added bonus, soon you will develop your own collection of reusable objects, which you will be able to leverage in other projects.

Finally, You will also find that OOP based PHP is much easier to maintain and update.

OOP Challenges:

OO PHP does present some challenges when you first start out because you’ll need to learn to think about your PHP projects in a different way: you will need to conceptualise the project in terms of objects.

More details …

One common way of starting an object-oriented project is to start by drawing up simple diagrams of your objects. As you begin to work with object diagrams, you will find that they help make developing OOP based PHP projects much easier.

Here are a few tips about drawing object-diagrams:

· Use a paper and pencil
· Draw boxes to represent each object
· In those boxes, list your methods and your properties
· Use arrows and lines between boxes to denote relationships (parent – child) between objects.

So if you have been sitting on the fence waiting to jump into OO PHP, now is as good time as any to get started.

Stefan Mischook

www.killerphp.com
www.killersites.com

Object Oriented PHP Tutorial Updated

Sunday, August 26th, 2007

php logo

Hi,

I’ve update my beginners tutorial on object oriented PHP adding steps 12-17. I cover two new basic OO concepts in these steps:

  • Constructors.
  • Access modifiers.

Again, this is a code intensive article where I expect you to follow along with your PHP editors.

More to come.

Thanks,

Stefan Mischook

www.killerphp.com

Object Oriented PHP Tutorial Released

Wednesday, August 22nd, 2007

php logo

Hi,

I’ve just released a written tutorial on object oriented PHP, that targets people totally new to OO PHP.

Beginners Object Oriented PHP

Based on an article I wrote for a web design magazine; the tutorial is presented as a series of simple steps where I walk the reader through the process of building objects while at the same time, exposing them to basic object oriented concepts.

The first 11 steps (of 23) are up now.

-

This tutorial is actually the outline to a set of videos I will be producing in the near future … Just as soon as I am finished with my dental work.

… It hurts I tells you!

Thanks for reading,

Stefan Mischook

www.killersites.com
www.killerphp.com

PHP Classes and Objects video tutorial

Friday, August 3rd, 2007

php logo

Hi,

I’ve released a new video that basically covers the content covered in the PDF: Classes and Objects.

-

… It is the last bit object oriented PHP theory before we jump in and start writing actual PHP code.

Video: PHP classes and objects

Thanks,

Stefan Mischook

Classes and Objects in PHP

Wednesday, August 1st, 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

Why Learn Object Oriented PHP – the PDF

Saturday, July 28th, 2007

php logo

I’ve just released a PDF that outlines the reasons for learning object oriented (OO) PHP.

PDF: why learn object oriented PHP

This document is meant to support my video on the same topic:

Video: why learn object oriented PHP.

Yes, this is basic stuff. But not everybody is a nerd-wizard.

-

I hope you guys find it useful.

Stefan Mischook

www.killerphp.com

Object Oriented PHP Videos are now out!

Friday, July 27th, 2007

Hi,

I’ve finally found the time to create a couple of videos on object oriented PHP!

The following videos are based on an article I wrote for Web Designer Magazine that taught OOP in PHP to total beginners.

Object Oriented Programming in PHP


OBJECT ORIENTED PHP VIDEOS

With the release of php5 (in 2004,) php programmers finally had the power to code with the ‘big boys’. Like Java and C#, php finally had a complete OOP infrastructure.

In these videos, you will be guided (step-by-step) through the process of building and working with objects using php’s built-in OOP capabilities. At the same time you will learn:

  • The difference between building a php application the old fashioned (procedural) way, versus the OOP way.
  • What the basic OOP principles are, and how to use them in PHP.
  • When you would want to use OOP in your PHP scripts.

People run into confusion when programming because of some lack of understanding of the basics. With this in mind, we are going to slowly go over key OOP principles (that are universal across many languages) while creating our own PHP objects.

With this knowledge, you will be able to explore OOP further.

I currently have these videos on line:

* Introduction to Object Oriented PHP
* Why learn Object Oriented PHP

I expect to have more videos out on OOP in PHP within the next week.

Thanks,

Stefan Mischook

www.killerphp.com
www.killersites.com

OOP in PHP: New PHP article to appear in Web Designer Magazine November’s Issue

Tuesday, November 7th, 2006

I have a new article appearing in issue 125 of Web Designer Magazine – the November issue.

Article title:

Learn Object Oriented Programming (OOP) in PHP

Object Oriented Programming in PHP

Sample from the article:

With the release of php5, php programmers finally had the power to code with the ‘big boys’. Like Java and C#, php finally has a complete OOP infrastructure.

In this tutorial, you will be guided (step-by-step) through the process of building and working with objects using php’s built-in OOP capabilities.

At the same time you will learn:

  • The difference between building a php application the old fashioned (procedural) way, versus the OOP way.
  • What the basic OOP principles are, and how to use them in PHP.
  • When you would want to use OOP in your PHP scripts.

People run into confusion when programming because of some lack of understanding of the basics. With this in mind, we are going to slowly go over key OOP principles while creating our own PHP objects. With this knowledge, you will be able to explore OOP further.

For this tutorial, you should understand a few PHP basics: functions, variables, conditionals and loops.

The article is broken down into 23 digestible steps with plenty of screen shots – makes it really easy to take in the information.

By the end of the article you will have your hands dirty with OOP PHP code … there is not better way to learn programming than to write code!

… I plan (at some point in the near future,) to put out a video tutorial to complement this article.

Thanks,

Stefan Mischook

PHP Interfaces: when and why you should use them instead of classes?

Saturday, August 26th, 2006

In this article/podcast, I look at what php interfaces are, and when and why we would use them over classes.

AUDIENCE:

To follow along, you must know the basics of object oriented php.

-

Download the MP3: PHP Interfaces Explained.

The following notes are meant to support the podcast … I left the details in the podcast.

First, what are interfaces?

  • Interfaces are 100% abstract classes – they have methods but the methods have no ‘guts’.
  • Interfaces cannot be instantiated – they are a construct in OOP that allows you to inject ‘qualities’ into classes .. like abstract classes.
  • Where an abstract class can have both empty and working/concrete methods, interface methods must all be shells – that is to say, it must be left to the class (using the interface) to flesh out the methods.

Example of a class:

class dog {

function bark() {
echo “yap, yap, yap …”;
}

}

Example of an interface:

interface animal {
function breath();
function eat();
}

Note: the interface’s functions/methods cannot have the details/guts filled in – that is left to the class that uses the interface.

Example of a class using an interface:

class dog implements animal{

function bark() {
echo “yap, yap, yap …”;
}

/* the interface methods/functions must be implemented (given their ‘guts’) in the class */

function breath() { echo “dog is breathing …”;}

function eat() { echo “dog is easting …”;}

}

/*

Remember: when a class uses/implements an interface, the class MUST define all the methods/functions of the interface otherwise the php engine will barf … ‘barf’ is a technical term for: give you an error.

*/

PRIMARY PURPOSES OF AN INTERFACE:

  • Interfaces allow you to define/create a common structure for your classes – to set a standard for objects.
  • Interfaces solves the problem of single inheritance – they allow you to inject ‘qualities’ from multiple sources.
  • Interfaces provide a flexible base/root structure that you don’t get with classes.
  • Interfaces are great when you have multiple coders working on a project – you can set up a loose structure for programmers to follow and let them worry about the details.

WHEN SHOULD YOU MAKE A CLASS AND WHEN SHOULD YOU MAKE AN INTEFACE?

  • If you have a class that is never directly instantiated in your program, this is a good candidate for an interface. In other words, if you are creating a class to only serve as the parent to other classes, it should probably be made into an interface.
  • When you know what methods a class should have but you are not sure what the details will be.
  • When you want to quickly map out the basic structures of your classes to serve as a template for others to follow – keeps the code-base predictable and consistent.

MISC. NOTES:

  • The ‘Holy Grail’ of programming is the reuse of existing code – interfaces play an important role in this.
  • Remember to push up all the code (up the class hierarchy,) to the highest level class. Interfaces help to make this happen.

-

If you find anything to be unclear, please let me know (make a comment) and I will do my best to clarify.

Top of page  go to top of page