Skip to content

Instantly share code, notes, and snippets.

@pgampe
Last active December 14, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgampe/5066866 to your computer and use it in GitHub Desktop.
Save pgampe/5066866 to your computer and use it in GitHub Desktop.
<?php
/**
* Test class
*/
class Foo {
public $bar = 'test';
private $baz = '123';
/**
* @param string $test
*/
public function testPublic($test) {
$this->baz = $test;
}
/**
* @param string $test
*/
protected function testProtected($test) {
$this->bar = $test;
}
/**
* @param string $name
* @param array $arguments
*/
public function __call($name, array $arguments) {
if (method_exists(__CLASS__, $name)) {
$this->$name($arguments[0]);
}
}
}
$foo = new Foo();
$foo->testPublic('other');
$foo->testProtected('Calling a protected function works.');
echo($foo->bar . chr(10));
$i = 0;
$start = microtime(TRUE);
for ($i = 0; $i < 1000; $i++) {
$foo->testPublic('test');
}
$middle = microtime(TRUE);
for ($i = 0; $i < 1000; $i++) {
$foo->testProtected('test');
}
$end = microtime(TRUE);
echo ('Public: ' . ($middle - $start) . 'ms' . chr(10));
echo ('Protected: ' . ($end - $middle) . 'ms' . chr(10));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment