Exemple #1
0
{
    protected static $cnt = 0;
    private $id;
    public static function getCount()
    {
        return static::$cnt;
    }
    public function __construct()
    {
        parent::__construct();
        $this->id = self::$cnt++;
        echo 'Daughter #' . $this->id . PHP_EOL;
    }
}
function spawn()
{
    $rand = rand(1, 15);
    $rand2 = rand(1, 15);
    for ($x = 0; $x < $rand; $x++) {
        $a[] = new MySon();
    }
    for ($x = 0; $x < $rand2; $x++) {
        $b[] = new MyDaughter();
    }
    // for($x=0; $x<sizeof($a)+sizeof($b);$x++)
}
spawn();
echo 'Il y a ' . MyClass::getCount() . ' instance de myClass' . PHP_EOL;
echo 'Il y a ' . MyDaughter::getCount() . ' instance de myDaughter' . PHP_EOL;
echo 'Il y a ' . MySon::getCount() . ' instance de mySon' . PHP_EOL;
//echo 'Il y a ' . MyClass::getCount() . ' instance de myClass' . PHP_EOL;
<?php

/**
 * White Spaces...
 */
for ($i = 0, $j = 0; $i < 8 && $j > 0; $i++, --$j) {
    echo $i . $j;
}
$a = array(1, 2, 3, 4 => 'four');
if ($a[1] >= 5) {
    switch ($a[2]) {
        case 3:
            return !($a[0] > 0);
            break;
        default:
            return $a[0] > 2 ? 10 : 20;
    }
}
$s = $a[2];
$c = new MyClass($s, $a);
$c->getCount();
$c = ++$s + $a[0]--;
echo "id = " . MyClass::ID;