Re: [PHP-DEV] on the subject of overloading: __call()

2002-11-18 Thread Stanislav Malyshev
BB>> but there is no way to make equivalent calls using call_user_func()
BB>> or call_user_func_array(). you can't use "parent::a_method",
BB>> array($this,'parent::a_method'), array(parent,"a_method"),
BB>> or array('parent',"a_method"). if you use the literal class name,
BB>>call_user_func_array(array(get_parent_class($this),'a_method'), $args);
BB>> it doesn't fail, but it's as if you were making a static method call
BB>> from outside of an object context - $this is not defined.

I fear you lost me here. Is the "a_method" static method or not? If yes - 
why not pass $this? If not - why do you need $this?

I will look into your examples later and respond what I think.

-- 
Stanislav Malyshev, Zend Products Engineer   
[EMAIL PROTECTED]  http://www.zend.com/ +972-3-6139665 ext.109









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




Re: [PHP-DEV] on the subject of overloading: __call()

2002-11-17 Thread Brad Bulger
On Sun, 17 Nov 2002, Stanislav Malyshev wrote:

> BB>> related topic: in the current state of ze2, there are several ways to
> BB>> call methods directly that can't be emulated by call_user_func() -
> BB>> calling self::method() for instance, or the visibility of $this if
> BB>> you call class::method(). is that likely to stay true?
>
> Since __call is the method of the class, calling self::method can be
> achieved, I think. As for the second point - could you please explain
> furher what you mean, maybe with an example?

right, because static method calls don't get caught by __call, so you
always have $this.

the basic problem is that as it is now, if i do any of these

self::a_method($arg1,$arg2);
parent::a_method($arg1,$arg2);
some_other_class::a_method($arg1,$arg2);

inside of a class's method, $this is visible inside those called methods,
and points to the calling object.

but there is no way to make equivalent calls using call_user_func()
or call_user_func_array(). you can't use "parent::a_method",
array($this,'parent::a_method'), array(parent,"a_method"),
or array('parent',"a_method"). if you use the literal class name,
call_user_func_array(array(get_parent_class($this),'a_method'), $args);
it doesn't fail, but it's as if you were making a static method call
from outside of an object context - $this is not defined.

it's the last two cases - parent:: and some_other_class:: - that relate
to __call(), as you point out. and what truly matters is call_user_func_array(),
because not having it means you can't hand off the arguments from __call()'s
parameters to a method in the parent class or in some other class. not without
writing some pretty hacky eval() code, that is.

(btw, there should probably be a warning in the docs that methods that
are expecting to force their parameters to be references will not work
as expected when called by call_user_func_array().)

i'm attaching kind of long test case code & resulting output that
show what i mean.


z = {$this->z}\n";
}
else
{
print "\tbar::test - this is not set\n";
}
}
function __call($m,$a) {}
}
class base
{
var $z = 'initial value of z for base';
function test($x=NULL,$y=NULL)
{
print "\tthis is base::test x=".var_export($x,TRUE)." y=$y\n";
if (isset($this))
{
print "\tbase::test - this->z = {$this->z}\n";
}
else
{
print "\tbase::test - this is not set\n";
}
self::whoami('self::whoami from base::test');
}
function __call($m,$a) {}
function whoami($caller=NULL)
{
print "\twhoami caller=$caller: __CLASS__ = ".__CLASS__."\n";
$class = get_class(new self);
print "\twhoami caller=$caller: get_class(new self) = $class\n";
$class = get_class('self');
print "\twhoami caller=$caller: get_class('self') = $class\n";
if (isset($this))
{
$class = get_class($this);
}
else
{
$class = '$this is not set';
}
print "\twhoami caller=$caller: get_class(this) = $class\n";
}
}
class foo extends base
{
var $z = 'initial value of z for foo';
function test($x=NULL,$y=NULL)
{
print "\tthis is foo::test x=".var_export($x,TRUE)." y=$y\n";
if (isset($this))
{
print "\tfoo::test - this->z = {$this->z}\n";
}
else
{
print "\tfoo::test - this is not set\n";
}
self::whoami('self::whoami from foo::test');
}
function test_parent($x=NULL,$y=NULL)
{
ob_start();

$results = '';
$results .= "this is foo::test_parent x=".var_export($x,TRUE)." 
y=$y\n";
if (isset($this))
{
$results .= "foo::test_parent - this->z = {$this->z}\n";
}
else
{
$results .= "foo::test_parent - this is not set\n";
}

$results .= "\n-\n";
$results .= __CLASS__.'::'.__FUNCTION__.'['.__LINE__.'] 
parent::test($x,$y);'."\n";
parent::test($x,$y);
$results .= "\nbegin results:\n".ob_get_contents()."\nend results\n";
$results .= "\n-\n";
@ob_clean();

$results .= "\n-\n";
$results .= __CLASS__.':

Re: [PHP-DEV] on the subject of overloading: __call()

2002-11-17 Thread Stanislav Malyshev
BB>> related topic: in the current state of ze2, there are several ways to
BB>> call methods directly that can't be emulated by call_user_func() -
BB>> calling self::method() for instance, or the visibility of $this if
BB>> you call class::method(). is that likely to stay true?

Since __call is the method of the class, calling self::method can be 
achieved, I think. As for the second point - could you please explain 
furher what you mean, maybe with an example?

-- 
Stanislav Malyshev, Zend Products Engineer   
[EMAIL PROTECTED]  http://www.zend.com/ +972-3-6139665 ext.109



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




[PHP-DEV] on the subject of overloading: __call()

2002-11-15 Thread Brad Bulger
was there discussion about the interaction of __call() and
methods which declaring their arguments as references?
there's no way at present to make this work, as far as i can tell.
seems like it could just be a documented limitation, but i thought
i'd check.

related topic: in the current state of ze2, there are several
ways to call methods directly that can't be emulated by
call_user_func() - calling self::method() for instance, or
the visibility of $this if you call class::method().
is that likely to stay true?


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