Page 1 of 1

classes

Posted: Sat Oct 01, 2005 1:18 pm
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

Posted: Sat Oct 01, 2005 1:32 pm
by Jenk

Posted: Sat Oct 01, 2005 2:11 pm
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().

Posted: Sun Oct 02, 2005 6:22 am
by AndrewBacca
cheers I remember now :)

Andrew