RE: __call and recursion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Daniel,

Could you please tell us what version of PHP and OS you're using.

The following code fragment runs as expected on my PHP 5.3.2/Windows/XP/32bit:

<?php

	header('Content-Type: text/plain');

	class A
	{
		private function method_a( $argument )
		{
			echo('private method_a(\'' . $argument . '\') ...' . PHP_EOL );
		}
		
		public function __call( $method, $arguments )
		{
			if( method_exists( $this, $method ) && is_callable( array( $this, $method ) ) )
			{
				call_user_func_array( array( $this, $method ), $arguments );
			}
			else
			{
				echo('method \'' . $method . '\' either does not exist, or is not callable ...' . PHP_EOL );
			}
		}
	}
	
	$a = new A();
	
	$a->method_a('argument');

	$a->method_b('argument');

?>

Results in:

private method_a('argument') called ...
method 'method_b' either does not exist, or is not callable ...


Perhaps if you provided some code we could spot the problem.

I would guess there's something fishy in your __call() method.

Best of luck,
Lawrance

-----Original Message-----
From: Richard Quadling [mailto:rquadling@xxxxxxxxxxxxxx] 
Sent: 12 May 2010 12:28 PM
To: Daniel Kolbo
Cc: PHP General
Subject: Re:  __call and recursion

On 9 May 2010 22:21, Daniel Kolbo <kolb0057@xxxxxxx> wrote:
> Hello,
>
> I've defined a __call() method inside a class.  Within the __call()
> method (after testing that the method exists and is callable I am using:
>
> call_user_func_array(array($this,$method), $args);
>
> However, this seems to be an infinite loop (and is crashing my test
> apache server).  How, could I still use the __call() method and avoid an
> infinite loop of calling?
>
> Thanks,
> dK

__call() is receiving $method.

Do you alter $method in any way?

If not, calling call_user_func(array($this, $method), $args) will
simply call the non-existent function.




-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux