Esempio n. 1
0
<?php

error_reporting(0);
something::do_something();
// $not_there is really NULL
var_dump($not_there);
// error occurs here: execution should never get inside the if condition because $not_there is NULL
if ($not_there["invalid_var"]) {
    // will print NULL (which is ok, but execution should never get here if the value is NULL)
    var_dump($not_there["use_authmodule"]);
    // will print "PATH:Array"
    print "PATH:" . $not_there["use_authmodule"] . "\n";
}
class something
{
    public static function get_object()
    {
        static $object = NULL;
        if ($object === NULL) {
            $object = new something();
        }
        return $object;
    }
    public static function do_something()
    {
        self::get_object()->vars[] = 1;
        self::get_object()->vars[] = 2;
        self::get_object()->vars[] = 3;
        var_dump(self::get_object()->vars);
    }
}
Esempio n. 2
0
    }
    public function dosomethingelse()
    {
        $i = 0;
        $i++;
    }
}
$start = microtime(true);
for ($c = 0; $c < 1000000; $c++) {
    dosomething();
}
echo "First loop took " . (microtime(true) - $start) . " seconds\n";
$start = microtime(true);
for ($c = 0; $c < 1000000; $c++) {
    $i = 0;
    $i++;
}
echo "Second loop took " . (microtime(true) - $start) . " seconds\n";
$foo = new something();
$start = microtime(true);
for ($c = 0; $c < 1000000; $c++) {
    $foo->dosomethingelse();
}
unset($foo);
echo "Third loop took " . (microtime(true) - $start) . " seconds\n";
$foo = new something();
$start = microtime(true);
for ($c = 0; $c < 1000000; $c++) {
    something::dosomething();
}
echo "Fourth loop took " . (microtime(true) - $start) . " seconds\n";