#24105 [Opn->Csd]: class member functions aren't first class data objects

From: Date: Sat, 28 Jun 2003 14:56:34 +0000
Subject: #24105 [Opn->Csd]: class member functions aren't first class data objects
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969354919@lists.php.net to get a copy of this message
ID: 24105 Updated by: helly@php.net Reported By: knotwell at ix dot netcom dot com -Status: Open +Status: Closed Bug Type: Documentation problem PHP Version: 4.3.1 New Comment: No, you're not requesting introspection here (btw. we will have that in php5). What you want are function pointers. and your second example is only the problem rewritten. Look at sniper's mail for the solution. If you want to pass object and method the notation is array($obj,$methodname). Previous Comments: ------------------------------------------------------------------------ [2003-06-10 00:42:02] knotwell at ix dot netcom dot com So the methodology for this is (what I presume to be)introspection, if possible, I'd suggest the addition to the documentation address the following similar case as well: class z { function b($x,$y) { return $x*$y; } } $a = new z; $b = $a->b; $b(3,4) --> an error from the runtime system. ------------------------------------------------------------------------ [2003-06-09 23:28:34] sniper@php.net It's by design. You're supposed to pass a string there, see below: <?php function generic_data_handler($specializedFn,$specializedFnData) { return $specializedFnData->$specializedFn($specializedFnData); } class z { var $x = 10; var $y = 4; function _mult($me) { return($me->x * $me->y); } function aStupidlyContrivedExample() { return generic_data_handler('_mult', $this); } } $a = new z; print $a->_mult($a); // an error from the runtime system print $a->aStupidlyContrivedExample(); ?> ------------------------------------------------------------------------ [2003-06-09 19:32:10] knotwell at ix dot netcom dot com I've checked the documentation, but it doesn't address this issue. As a result, I'm unsure if this is a bug or by design. Anyhow, it appears class functions aren't first class data objects. I've included a short example leading to a "Call to undefined function" message as a example: <?php function generic_data_handler($specializedFn,$specializedFnData) { return $specializedFn($specializedFnData); } class z { var $x = 10; var $y = 4; function _mult($me) { return($me->x * $me->y); } function aStupidlyContrivedExample() { return generic_data_handler($this->_mult,$this); } } $a = new z; print $a->_mult($a); // an error from the runtime system print $a->aStupidlyContrivedExample(); ?> Apologies in advance if this is common knowledge or not a bug. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=24105&edit=1

« previous php.doc (#969354919) next »