|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-06-09 19:32 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 15:00:02 2025 UTC |
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(); ?>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.