hi everyone,
im using overloading, especially __get(), to simplify chaining of objects like this
now i get this error-message:PHP Code:$this->context->user->attributes->userID = 1;
context has an protected attribute $user, so php should trigger __get() to dispatch this call but it doesn't! it tries to access the property directly which does not work.Code:"Fatal error: Cannot access protected property Radix_Context::$user in <file> on line <line>"
on the other hand, this testcase works like a charm:
i already sent this problem to the german mailinglist located at phpbar.de and johannes schlueter answered, stating that this procedure is absolutely normal.PHP Code:class OverloadingDispatcher
{
function __get($name)
{
return call_user_func(array($this , "get{$name}"));
}
}
class Root extends OverloadingDispatcher
{
protected $a;
function __construct()
{
$this->a = new A();
}
function getA()
{
return $this->a;
}
}
class A extends OverloadingDispatcher
{
protected $b;
function __construct()
{
$this->b = new B();
}
function getB()
{
return $this->b;
}
}
class B extends OverloadingDispatcher
{
protected $c;
function __construct()
{
$this->c = new C();
}
function getC()
{
return $this->c;
}
}
class C
{
function sayHello()
{
echo 'hello world!';
}
}
$r = new Root();
$r->a->b->c->sayHello();
php checks the properties visibility and than refuses to call the magic-overloading-functions.
anyone any hint?
thanks!
kai





Bookmarks