<?php
class Base
{
public static function foo()
{
return static::class;
}
public static function bar()
{
return get_called_class();
}
}
class Child extends Base {}
profile("Parent, static::class", function () { Base::foo();});
profile("Parent, get_called_class", function () { Base::bar();});
profile("Child, static::class", function () { Child::foo();});
profile("Child, get_called_class", function () { Child::bar();});
function profile($what, callable $func) {
static $previous;
if (!$previous) $previous = microtime(true);
for ($a = 0; $a<=1000000; $a++) { $func(); };
$now = microtime(true);
echo sprintf("%s took %.4f seconds", $what, $now - $previous), PHP_EOL;
$previous = $now;
}
preferences:
42.13 ms | 405 KiB | 5 Q