note 98656 added to function.create-function

From: Date: Tue, 29 Jun 2010 15:02:04 +0000
Subject: note 98656 added to function.create-function
Groups: php.notes 
Request: Send a blank email to php-notes+get-170548@lists.php.net to get a copy of this message
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 ---- Server IP: 64.71.164.2 Probable Submitter: 173.67.25.6 ---- Manual Page -- http://www.php.net/manual/en/function.create-function.php Edit -- https://master.php.net/note/edit/98656 Del: integrated -- https://master.php.net/note/delete/98656/integrated Del: useless -- https://master.php.net/note/delete/98656/useless Del: bad code -- https://master.php.net/note/delete/98656/bad+code Del: spam -- https://master.php.net/note/delete/98656/spam Del: non-english -- https://master.php.net/note/delete/98656/non-english Del: in docs -- https://master.php.net/note/delete/98656/in+docs Del: other reasons-- https://master.php.net/note/delete/98656 Reject -- https://master.php.net/note/reject/98656 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170548) next »