/** * @param $object * @param $value * * @return mixed The new value */ public function set($object, $value) { $this->setter->set($object, $value); return $value; }
public function testHasCorrectShortName() { $setter = new Setter([]); $this->assertSame('Setter', $setter->getShortName()); }
} } public function __set($key, $value) { if (array_key_exists($key, $this->vars)) { $this->vars[$key] = $value; } } public function __get($key) { if (array_key_exists($key, $this->vars)) { return $this->vars[$key]; } } } $class = new Setter(); $class->setPartnerName('partnerName'); var_dump($class->partnerName); echo "\n--- Testing objects ---\n"; /* we get "Catchable fatal error: saying Object of class could not be converted to string" by default when an object is passed instead of string: The error can be avoided by choosing the __toString magix method as follows: */ class string { function __toString() { return "Hello world"; } } $obj_string = new string(); var_dump(lcfirst("{$obj_string}"));