|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #10743 Allow using list, new, etc. as class method names
Submitted: 2001-05-09 03:42 UTC Modified: 2012-06-05 22:59 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jjones at net-conex dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jjones at net-conex dot com
New email:
PHP Version: OS:


 [2001-05-09 03:42 UTC] jjones at net-conex dot com
Okay.. this has been bugging me for a while..
consider the following:
class test {
function mail () { print ("Bah\n"); }
function fopen () { print ("Bah\n"); }
function new () { print ("Bah\n"); }
function list () { print ("Bah\n"); }
$temp = new test;
etc, etc..

This will generate a parse error (expecting `T_STRING') until the new() and list() functions are removed from the class.  mail() and fopen() will work.
Now.. my question is why the inconsistency?
Is there some super-secret reasoning behind not letting me name my classes' objects the same as only a few predefined functions?
I'm lazy.. you guys took all the good function names.. why must you tease me with them?!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-09 03:52 UTC]
New and list are language contructs, and not functions in PHP. That's why those don't work.
This is not a bug, so bugusfying this report.
 [2001-05-09 05:02 UTC]
IMHO the parser should be clever enough to get the 
clue when using new() or list() in a class/method
context that these can't be referencing the language 
constructs here

moved to feature requests
 [2003-08-11 16:21 UTC] destes at ix dot netcom dot com
yes, but couldn't any later calls to those new() and list() functions result in parsing clashes?  If so, perhaps the error message should be clarified.

That's one of the few glaring insufficiencies in PHP right now - the clarity of its errors, especially its parse errors.  

If the parser isn't going to be made intelligent enough to allow you to make functions like a new() or list() - and I can see the argument, considering some language constructs can be invoked using function syntax - then at least make a prettier error message =)

 [2010-11-24 13:53 UTC]
-Summary: class functions & PHP core functions inconsistently clash ;) +Summary: Allow using list, new, etc. as class method names -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: Linux +Operating System: * -PHP Version: 4.0.4pl1 +PHP Version: *
 [2012-06-05 22:59 UTC]
Closing this as a duplicate to It's newer, but it has a bit more discussion and a (not yet correctly working) patch.
 [2012-06-05 22:59 UTC]
-Status: Open +Status: Duplicate
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 08:01:43 2024 UTC