classes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

classes

Post by AndrewBacca »

I have just seen some a php class

class2 extends class1

can any1 tell me the use of this?

because I have seen that before in C++ years ago but can't remember, and I am tring to create a php software package that is as OO as possible and that my come in handy :)

Andrew
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

When you extend a class, you create another class that's built on top of the first class. You retain all the functionality of the first class, and add to it with functions from the second class.

ex:

Code: Select all

class Vehicle
{
   function turn($direction)
   {}
   function accelerate($rate)
   {}
}

class FighterJet extends Vehicle
{
    function eject()
    {}
    function shoot()
}
Since FighterJet extends Vehicle, it can turn() and accelerate(). It can also eject() and shoot(). If one were to create an instance of Vehicle, you would only get to turn() and accelerate().
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

cheers I remember now :)

Andrew
Post Reply