Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP 7.1
- Magic methods:
- php -d implicit_flush=off -r 'class dog {private $name = ""; public function __get($property) { if (property_exists($this, $property)) { return $this->$property; } } public function __set($property, $value) { if (property_exists($this, $property)) { $this->$property = $value; } } } $rover = new dog(); for ($x=0; $x<10; $x++) { $t = microtime(true); for ($i=0; $i<1000000; $i++) { $rover->name = "rover"; $n = $rover->name;} echo microtime(true) - $t;echo "\n";}'
- 0.57930207252502
- 0.5767650604248
- 0.5775511264801
- 0.5777759552002
- 0.57945394515991
- 0.57729411125183
- 0.57919216156006
- 0.57855105400085
- 0.579097032547
- 0.5776948928833
- Getter and Setter:
- php -d implicit_flush=off -r 'class dog {private $name = "";public function setName($name) {$this->name = $name; }public function getName() {return $this->name; } }$rover = new dog();for ($x=0; $x<10; $x++) { $t = microtime(true);for ($i=0; $i<1000000; $i++) { $rover->setName("rover");$n = $rover->getName();}echo microtime(true) - $t;echo "\n";}'
- 0.13011598587036
- 0.13124799728394
- 0.13241600990295
- 0.1318941116333
- 0.13171601295471
- 0.13296389579773
- 0.13102602958679
- 0.13133406639099
- 0.13163495063782
- 0.13129711151123
- Accessing property directly:
- php -d implicit_flush=off -r 'class dog { public $name = "";} $rover = new dog(); for ($x=0; $x<10; $x++) { $t = microtime(true); for ($i=0; $i<1000000; $i++) { $rover->name = "rover"; $n = $rover->name;} echo microtime(true) - $t;echo "\n";}'
- 0.051743984222412
- 0.051209926605225
- 0.051720142364502
- 0.050024032592773
- 0.049885988235474
- 0.051983118057251
- 0.049699068069458
- 0.050537824630737
- 0.050158023834229
- 0.049751996994019
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement