note 30880 deleted from function.create-function by danbrown

From: Date: Sat, 19 Jul 2008 21:26:41 +0000
Subject: note 30880 deleted from function.create-function by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141756@lists.php.net to get a copy of this message
Note Submitter: DB on music_ml at yahoo dot com dot ar ---- Apparently you can't refer to a class variable from an anonymous-defined function, inside a class method, using the $this keyword: <?php class AnyClass { var $classVar = 'some regular expression pattern'; function classMethod() { $_anonymFunc = create_function( '$arg', 'if ( eregi($this->classVar, $arg) ) { return true; } else { return false; } ' ); $wontWork = $_anonymFunc('some string'); } } ?> This would throw a warning on 'undefined variable: this'...

« previous php.notes (#141756) next »