Skip to content

Instantly share code, notes, and snippets.

@danslo
Created August 6, 2013 20:18
Show Gist options
  • Save danslo/6168214 to your computer and use it in GitHub Desktop.
Save danslo/6168214 to your computer and use it in GitHub Desktop.
<?php
class Test {
protected $_data = array();
public function __call($method, $args) {
if (substr($method, 0, 3) == 'set') {
$key = strtolower(substr($method, 3));
if (isset($args[0])) {
$this->_data[$key] = $args[0];
}
}
}
public function dump() {
var_dump($this->_data);
}
}
$test = new Test();
// (obviously) works
$test->setHello('world');
// also works
call_user_func_array(array($test, 'setThis'), array('is cool'));
// doesn't work
call_user_func_array(array($test, 'setFoo'), array('bur' => 'bar'));
$test->dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment