note 40227 deleted from language.oop by aidan
| From: | aidan@php.net | Date: | Sat, 03 Jul 2004 14:48:40 +0000 |
| Subject: | note 40227 deleted from language.oop by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72435@lists.php.net to get a copy of this message | ||
Note Submitter: bgano@inocompany.com
----
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();
?>