php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45077 Eval Does Not Work Inside Class Definition
Submitted: 2008-05-23 07:14 UTC Modified: 2008-05-23 10:42 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dimo414 at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.6 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dimo414 at gmail dot com
New email:
PHP Version: OS:

 

 [2008-05-23 07:14 UTC] dimo414 at gmail dot com
Description:
------------
Attempting to create a dynamic class definition using eval() to define segments of the class on the fly, fails as PHP does not allow for eval() to be called during class definition.  This may be more of a feature request than a bug, but it would seem to me that PHP should allow eval() to operate as normal inside class definitions.

Reproduce code:
---------------
class foo
{
  eval('var $bar;');
  
  function test($input)
  {
    $bar = $input;
  }
}

Expected result:
----------------
Should create a class called foo with one attribute, $bar, and a constructor which takes one parameter.

Actual result:
--------------
Parse error: syntax error, unexpected T_EVAL, expecting T_FUNCTION in W:\www\Internal\foo.class.php on line 3


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-23 10:42 UTC] colder@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Class definitions are not supposed to be dynamic. And extending the language in order to allow evals in classes definition would be a really bad thing to do.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 05:00:01 2025 UTC