php.net |  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
Votes:1
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
8 + 22 = ?
Subscribe to this entry?

 
 [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;
$temp->mail();
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?!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-09 03:52 UTC] derick@php.net
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] hholzgra@php.net
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 =)

-Steve
 [2010-11-24 13:53 UTC] jani@php.net
-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] nikic@php.net
Closing this as a duplicate to https://bugs.php.net/bug.php?id=28261. It's newer, but it has a bit more discussion and a (not yet correctly working) patch.
 [2012-06-05 22:59 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 07:01:27 2024 UTC