Witam mam problem z metodą __get().
Kod:
abstract class Properties {
function __get($property) {
echo "W __get()";
$method = "get{$property}";
if (method_exists($this, $method)) {
return $this->$method;
}
}
function __isset($property) {
$method = "get{$property}";
return method_exists($this, $method);
}
function __set($property, $value) {
echo "W __set()";
$method = "set{$property}";
if (method_exists($this, $method)) {
return $this->$method($value);
}
}
function __unset($property) {
$method = "set{$property}";
if (method_exists($this, $method)) {
return $this->$method(null);
}
}
}
class Foo extends Properties {
private $prop;
public function setProp($value) {
$this->prop = $value;
}
public function getProp() {
echo "W getProp()";
return $this->prop;
}
public function sayHello() {
echo "I am saying hello!";
}
}
$obj = new Foo();
echo $obj->sayHello();
$obj->prop = "Hello World";
print $obj->prop;
print $obj->getProp();
Wynik działania:
I am saying hello!W __set()W __get()W __get()W getProp()Hello World
Albom ślepy i jakaś literówka, albo nie wiem co jest nie tak, czemu __get() nie spełnia swojego zadania?
Pozdrawiam
Brakowało głupich nawiasów, eh... sorry za syf