Esempio n. 1
0
class Car extends Vehicle{
    public $gas;

    function __construct()
    {
        parent::__construct("car",4);
        $this->gas = 100;
    }
    function drive(){
        parent::drive();
        $this->gas-= 5;
        echo "Now I have $this->gas percent of gas left.<br>";}
}

$bike = new Bicycle("bell");
echo $bike->drive("bell"); //prints 'Riding a bike with 2 wheels'
echo '<br>';
$car = new Car();
echo $car->drive();//prints 'Driving a car with 4 wheels'

?>


</p>
<?php
/*
 *
 $_SESSION
$_POST
$_GET
Esempio n. 2
0
		<h2>Inheritance</h2>
		<?php 
$square = new Square();
if (property_exists($square, "hasSides")) {
    echo "I have sides";
}
?>

		<h2>Overriding Parent Methods</h2>
		<?php 
$vehicle = new Vehicle();
echo $vehicle->honk() . "<br/>";
$bicycle = new Bicycle();
echo $bicycle->honk() . "<br/>";
echo $bicycle->drive() . "<br/>";
?>
		<h2>Using <code>const</code></h2>
		<?php 
// :: => scope resolution operator
if (Immortal::alive) {
    echo "I live forever!";
}
?>

		<h2><code>static</code> Keyword</h2>
		<?php 
echo Person::greet() . "<br/>";
echo Person::$shout . "<br/>";
?>
	</body>