Ejemplo n.º 1
0
    }
}
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)!";
}
?>
        <h1>Iterating Through Loops</h1>
        <h3>Foreach as $key => $value</h3>
            <?php 
$example = array("Hello", "World", "Foo", "Bar");