note 30880 modified in function.create-function by aidan
| From: | aidan@php.net | Date: | Sun, 20 Jun 2004 06:17:54 +0000 |
| Subject: | note 30880 modified in function.create-function by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71391@lists.php.net to get a copy of this message | ||
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'...
--was--
Apparently you can't refer to a class variable from an anonymous-defined function, inside a
class method, using the $this keyword:
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'...
http://php.net/manual/en/function.create-function.php