| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2004-05-03 17:36 UTC] Philippe dot Jausions at 11abacus dot com
 Description:
------------
Suggestion:
Wouldn't it be possible to lift the reserved keyword restriction for method names?
It seems to me that there shouldn't be any namespace conflict with the core PHP language.
Reproduce code:
---------------
<?php
class a {
   function eval() {
      // Do something...
   }
}
?>
Actual result:
--------------
Parse error: parse error, unexpected T_EVAL, expecting T_STRING
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 11:00:01 2025 UTC | 
as new reserved words are introduced, they tend to clash with existing class's method names. import and namespace are particularly nasty examples of methods that are likely to clash, although I have also run into problems with "list" which is a very nice method name for many tasks. The patches linked to in this comment provides a simple and effective means of allowing reserved words in method names. Not only is it possible, but it is quite elegant :). It also fixes, as a side effect, a bug in the parsing of this code: <?php class A { var $list; } $a = new A; $a->list = 1; $a-> list = 2; // parse error, unexpected T_LIST ?> whitespace between T_OBJECT_OPERATOR and the variable name changes the token returned from T_STRING to any valid token. Patch for PHP 5: http://pear.php.net/~greg/smarter_lexer.patch.txt Patch for PHP 6: http://pear.php.net/~greg/php6_smarter_lexer.patch.txtAt the moment (5.2.3 ) this is perfectly valid. Class A{ function __call( $function, $args ){ if( $function == 'print' ){ print "MyPrint: {$args[0]}"; } } } $a = new A(); $a->print( "hello" ); #<-- surprisingly, this is not an invalid use of a keyword to the lexer. # >> MyPrint: hello but this Class A{ function print( $args ){ print "MyPrint: {$args}"; } } $a = new A(); $a->print( "hello" ); Yields a parse error "Parse error: syntax error, unexpected T_PRINT, expecting T_STRING" which appears to be an illogical design contstraint. I've seen rather brutal slander for people attempting to perform this ( #14178 , this bug ) amounting to "hey, you suck, dont do that" without any rational explanation. So yes, I look forward to this feature being integrated.