note 98656 deleted from function.create-function by danbrown
| From: | danbrown@php.net | Date: | Tue, 29 Jun 2010 15:36:47 +0000 |
| Subject: | note 98656 deleted from function.create-function by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170551@lists.php.net to get a copy of this message | ||
Note Submitter: RC
----
One would assume that this would work:
<?php
class Test {
private $var;
function a() { $this->var = 'date' }
function b() { echo( $this->var('r')); }
}
?>
Turns out this doesn't work, even though it should. As is shown in several other posts, it does
work for public $var.
Oddly, while it doesn't work, it also doesn't throw any errors such as the fatal error of
calling an undefined function, it simply does not execute anything within the function. You can test
this via a custom function or a create_function to see nothing is ever run.
The solution is to instead use:
<?php
function b() { echo call_user_func($this->var,'r'); }
?>
Looks like a bug in PHP regarding restricted access variables within an object being used for a
function call.
Running PHP 5.3.0