php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #59041 Don't use reseved method names
Submitted: 2010-01-23 03:06 UTC Modified: 2010-04-20 08:15 UTC
From: niko dot sams at gmail dot com Assigned: cataphract (profile)
Status: Closed Package: rar (PECL)
PHP Version: 5.2.11 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:
43 - 32 = ?
Subscribe to this entry?

 
 [2010-01-23 03:06 UTC] niko dot sams at gmail dot com
Description:
------------
The following method uses a php construct as name:
RarArchive::list

Please consider changing the name to avoid problems.

(similar report: http://pecl.php.net/bugs/bug.php?id=16900)

Reproduce code:
---------------
class MyClient extends RarArchive
{
    public function list()
    {}
}


Expected result:
----------------
I'd like to override the list method

Actual result:
--------------
I get a parse error from php

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-23 05:07 UTC] glopes at nebm dot ist dot utl dot pt
Thank you for your report.

As you point out, naming the method "list" was probably not a very good idea, however, RarArchive is a final class (and consequently your example is inapplicable) and I'm reluctant to change the API at this RC stage.

If, in the future, RarArchive is to become non-final, one can always make list() final and introduce a new method, called by list(), that is overridable. 

So unless there are other cases wherein giving a reserved name to a method will cause problems, I'm marking this Wont fix.
 [2010-01-23 05:25 UTC] niko dot sams at gmail dot com
The real reason why I'm reporting this, is because in KDevelop Php Language Support we generate a php file containing real php code with empty skeletons for all internal php functions and classes. And that file we parse using our parser to use it for code completion.
And our parser fails on this "list" function names - as the real php parser would.
Currently we have this class on a blacklist and can't provide code completion for it.
 [2010-01-23 10:54 UTC] cataphract@php.net
All right, I've reconsidered.

I've seen such stubs in other IDEs, such as NetBeans. There may be other places (present or future) in which using reserved words for method names are a problem, and this time is the last opportunity to keep them out of a stable API, so I'll be renaming RarArchive::list as RarArchive::getEntries as of 2.0.0 final.
 [2010-01-23 11:50 UTC] niko dot sams at gmail dot com
great, thanks.
 [2010-04-20 08:15 UTC] cataphract@php.net
Fixed in revision #298209.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC