Skip to content

Instantly share code, notes, and snippets.

@koesie10
Created February 2, 2013 14:35
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 koesie10/4697583 to your computer and use it in GitHub Desktop.
Save koesie10/4697583 to your computer and use it in GitHub Desktop.
<?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