# protected __call() question

- Thread: https://externals.io/message/8929
- Original archive: https://news-web.php.net/php.internals/8929
- Started by Jochem Maas on 2004-04-04T19:49:44+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #8929 — Jochem Maas — 2004-04-04T19:49:44+00:00

URL: https://externals.io/message/8929#8929

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.

Kind Regards,

Jochem.

---

## #8931 — Marcus Boerger — 2004-04-05T08:02:22+00:00

URL: https://externals.io/message/8929#8931 · In reply to: #8929

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.

---

## #8932 — Derick Rethans — 2004-04-05T08:12:35+00:00

URL: https://externals.io/message/8929#8932 · In reply to: #8931

> 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
