Created
February 2, 2013 14:35
-
-
Save koesie10/4697583 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class OverloadingClassFromHell | |
{ | |
private $data = array(); | |
public function __set($name, $value) | |
{ | |
$this->data[$name] = $value; | |
} | |
public function __get($name) | |
{ | |
if (array_key_exists($name, $this->data)) { | |
return $this->data[$name]; | |
} | |
} | |
} | |
class OverloadingClassFromHell2 | |
{ | |
private $data = array(); | |
public function set($name, $value) | |
{ | |
$this->data[$name] = $value; | |
} | |
public function get($name) | |
{ | |
if (array_key_exists($name, $this->data)) { | |
return $this->data[$name]; | |
} | |
} | |
} | |
$research = new Research('Magic vs Normal getter'); | |
$research->addTest(new Test('Magic', function() { | |
$class = new OverloadingClassFromHell(); | |
$class->gebruikersnaam = 'hallo'; | |
echo $class->gebruikersnaam; | |
})); | |
$research->addTest(new Test('Getters and setters', function() { | |
$class = new OverloadingClassFromHell2(); | |
$class->set('gebruikersnaam', 'hallo'); | |
echo $class->get('gebruikersnaam'); | |
})); | |
$research->runTests(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment