return $this->size;
    }
}
class Lion extends Feline
{
    public $size = 'large';
    public $hasMane = true;
}
class Tiger extends Feline
{
    public $size = 'large';
}
class HouseCat extends Feline
{
    public $size = 'small';
}
$lion = new Lion('Frog');
$tiger = new Tiger('Tubby');
$house_cat = new HouseCat('Snoopy');
echo 'Frog the Lion is ' . $lion->size . '.';
echo '<br>';
echo 'Tubby the tiger is ' . $tiger->size . '.';
echo '<br>';
echo 'Snoopy the house cat is ' . $house_cat->size . '.';
echo '<br>';
echo $lion->getSize();
echo '<br>';
echo $tiger->getSize();
echo '<br>';
echo $house_cat->getSize();
echo '<br>';
Example #2
0
<?php

error_reporting(E_ALL);
require 'Tiger/Tiger.php';
include APP_PATH . '/config.php';
$_tiger = new Tiger();
/* 优先级
 * 1配置,2错误处理,3语言
 */
$_tiger->setConfig($_config);
$_tiger->setHalt("handleErrorFuncForTiger");
$_lang = $_tiger->lang();
function handleErrorFuncForTiger($msg, $isI18nMsg = false, $level = 0)
{
    global $_tiger, $_lang;
    $c = $_tiger->error();
    if (true === $isI18nMsg) {
        $msg = $_lang->get($msg);
    }
    $c->call($msg);
}
Example #3
0
 public static function call(Tiger $animal)
 {
     $animal->climb();
 }
Example #4
0
        return "Meow meow." . '<br/>';
    }
    public final function no_extend()
    {
        return "This function cannot be redefined in child classes.";
    }
}
class Tiger extends Cat
{
    public function roar($name)
    {
        return "My name is {$name}. Hear me roar!" . '<br/>';
    }
}
$cat1 = new Cat("Felix");
$cat2 = new Tiger("Clemson");
echo $cat1::meow();
echo $cat2::meow();
// <- Works because Clementine is a type of cat, so the function extends.
//echo $cat1->roar("Felix"); <-- Doesn't work because Felix is defined as a cat and tiger methods don't extend backwards to cats.
echo $cat2->roar("Clementine");
echo Cat::numLegs;
if (is_a($cat1, "Cat")) {
    echo '<br/>' . "I am a cat (object Class), ";
}
if (property_exists($cat2, "name")) {
    echo "I have a name (property), ";
}
if (method_exists($cat2, "roar")) {
    echo "And hear me roar (method)!";
}