the following code does not do what I expect, I made this test case
after a new version of PHP5 was put on the system I am developing
yesterday and some of my code no longer works:
<?
Class CallMe
{
public function setup()
{
$this->fakeMethod();
}
protected function __call($method, $params)
{
echo 'you called CallMe::'.$method."\n";
}
}
echo <<< ___THEEND
EXPECTED RESULT:
you called CallMe::fakeMethod
ACTUAL RESULT:
___THEEND;
$obj = new CallMe();
$obj->setup();
?>
running the script on 'PHP 5.0.0RC2-dev (cli) (built: Apr 4 2004
13:07:13) (DEBUG)' gives me:
ACTUAL RESULT:
PHP Fatal error: Call to protected method CallMe::__call() from context
'' in /var/www/santos/test/call.protected.php on line 7
Fatal error: Call to protected method CallMe::__call() from context ''
in /var/www/santos/test/call.protected.php on line 7
</snip>
Have I misunderstood the way PHP5 works?
Or maybe something is broken? does anyone else get an error?
I don't rule out that this could be something specific to the machine I
am on, unfortunately I am limited by knowledge and access in determining
if this is the case.
Kind Regards,
Jochem.
Hello Jochem,
using 'protected' for __call() hides that mechanism from the outside world,
hence the behavior is correct. Just drop protected and it should work as you
expect.
marcus
Sunday, April 4, 2004, 9:49:44 PM, you wrote:
the following code does not do what I expect, I made this test case
after a new version of PHP5 was put on the system I am developing
yesterday and some of my code no longer works:
<?
Class CallMe
{
public function setup()
{
$this->fakeMethod();
}
protected function __call($method, $params) { echo 'you called CallMe::'.$method."\n"; }
}
echo <<< ___THEEND
EXPECTED RESULT:you called CallMe::fakeMethod
ACTUAL RESULT:
___THEEND;
$obj = new CallMe();
$obj->setup();
?>>
running the script on 'PHP 5.0.0RC2-dev (cli) (built: Apr 4 2004
13:07:13) (DEBUG)' gives me:
<snip> EXPECTED RESULT: ----------------------------------------- you called CallMe::fakeMethod
ACTUAL RESULT:
PHP Fatal error: Call to protected method CallMe::__call() from context
'' in /var/www/santos/test/call.protected.php on line 7
Fatal error: Call to protected method CallMe::__call() from context ''
in /var/www/santos/test/call.protected.php on line 7
</snip>
Have I misunderstood the way PHP5 works?
Or maybe something is broken? does anyone else get an error?
I don't rule out that this could be something specific to the machine I
am on, unfortunately I am limited by knowledge and access in determining
if this is the case.
Hello Jochem,
using 'protected' for __call() hides that mechanism from the outside world,
hence the behavior is correct. Just drop protected and it should work as you
expect.
But it is not called from the outside world ...
Derick