| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2001-02-06 17:38 UTC] waldschrott@php.net
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 15:00:01 2025 UTC | 
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);