note 40227 added to language.oop
| From: | bgano at inocompany dot com | Date: | Thu, 26 Feb 2004 02:07:55 +0000 |
| Subject: | note 40227 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65766@lists.php.net to get a copy of this message | ||
A note on using class members as function references. This will not work:
<?php
function MyFunction($output)
{
echo $output;
}
class MyClass
{
var $ref;
function MyClass()
{
$this->ref = "MyFunction";
${$this->ref}("doesn't work");
}
}
$obj = new MyClass();
?>
The only way I've found to allow class members to reference functions is by copying the
function name into a local variable before referencing it:
<?php
function MyFunction($output)
{
echo $output;
}
class MyClass
{
var $ref;
function MyClass()
{
$this->ref = "MyFunction";
$localRef = $this->ref;
$localRef("doesn't work");
}
}
$obj = new MyClass();
?>
----
Manual Page -- http://www.php.net/manual/en/language.oop.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40227
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40227&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40227&report=yes
Search -- http://master.php.net/manage/user-notes.php