PHP 4.0 Bug #9137: eval adds function to global space rather than class method

From: Date: Tue, 06 Feb 2001 22:32:47 +0000
Subject: PHP 4.0 Bug #9137: eval adds function to global space rather than class method
Groups: php.dev 
Request: Send a blank email to php-dev+get-45883@lists.php.net to get a copy of this message
From: aj@homeboyz.com Operating system: Linux PHP version: 4.0.4pl1 PHP Bug Type: Class/Object related Bug description: eval adds function to global space rather than class method I am trying to generate class methods on the fly. I created a string which was php code for a function. I wished this funciton to be a class method. I call eval on the string, and it produces no errors. When I wish to call that method of the object, the script fails indicating a call to an undefined funciton. However, I can call that function in the page space, rather than as a class method. But, the function is useless unless it is a method. The following is part of the code that is executed in the constructor: $str = ""; foreach($this->getMappedAttributes() as $attribute) { $str .= "$"."this->_".$attribute['attribute']." = \"\";"; $str .= "function get".$attribute['attribute']."() {"; $str .= "return $"."this->_".$attribute['attribute'].";}"; } eval($str); -- Edit Bug report at: http://bugs.php.net/?id=9137&edit=1

« previous php.dev (#45883) next »