Example #1
0
<?php

abstract class animal
{
    function makenoise()
    {
        echo $this->noise;
    }
}
//the extends bit is called inheritance. both classes cat and dog
//'inherit' makenoise from animal in this case
class cat extends animal
{
    public $noise = 'meow';
}
$cat = new cat();
$cat->makenoise();
class dog extends animal
{
    public $noise = 'woof';
}
$dog = new dog();
$dog->makenoise();
Example #2
0
File: oo.php Project: anatai/manray
<?php

class cat
{
    function makenoise()
    {
        return 'meow';
    }
    function speed()
    {
        return 'fast';
    }
}
$cat = new cat();
echo 'the cat says ' . $cat->makenoise() . ' and is very ' . $cat->speed();