[PHP-BUG] Bug #61275 [NEW]: Cannot have class method with same name as language construct
From: Operating system: Any PHP version: 5.4.0 Package: Compile Failure Bug Type: Bug Bug description:Cannot have class method with same name as language construct Description: It isn't possible to have a class method whose name is the same as any of the language constructs, e.g. array(), doing so creates a parse error as follows: PHP Parse error: parse error, expecting `T_STRING' in - on line 8 The error message is somewhat cryptic and confusing when it affects code which looks otherwise perfectly valid. This perhaps isn't a big deal for most people as the work around is to rename your method. It is a problem when using a different name for the method is undesirable (e.g. I'm creating a framework in PHP which emulates that from a different programming language, so ideally the method names should be the same). Test script: --- array(); class testClass { public function array() { echo("testClass::array() called."); } } ?> Expected result: testClass::array() called. Actual result: -- PHP Parse error: parse error, expecting `T_STRING' in - on line 8 -- Edit bug report at https://bugs.php.net/bug.php?id=61275&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61275&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61275&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61275&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61275&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61275&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61275&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61275&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61275&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61275&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61275&r=support Expected behavior: https://bugs.php.net/fix.php?id=61275&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61275&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61275&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61275&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61275&r=php4 Daylight Savings:https://bugs.php.net/fix.php?id=61275&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61275&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61275&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61275&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61275&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61275&r=mysqlcfg
Bug #61275 [Opn]: Cannot have class method with same name as language construct
Edit report at https://bugs.php.net/bug.php?id=61275&edit=1 ID: 61275 User updated by: php at mralston dot com Reported by: php at mralston dot com Summary:Cannot have class method with same name as language construct Status: Open Type: Bug -Package:Compile Failure +Package:Class/Object related Operating System: Any PHP Version:5.4.0 Block user comment: N Private report: N New Comment: Changed package field from 'Compile Failure' to 'Class/Object related', as 'Compile Failure' is probably intended to relate to problems compiling PHP itself, rather than PHP scripts. Previous Comments: -------- [2012-03-04 17:52:53] php at mralston dot com Description: It isn't possible to have a class method whose name is the same as any of the language constructs, e.g. array(), doing so creates a parse error as follows: PHP Parse error: parse error, expecting `T_STRING' in - on line 8 The error message is somewhat cryptic and confusing when it affects code which looks otherwise perfectly valid. This perhaps isn't a big deal for most people as the work around is to rename your method. It is a problem when using a different name for the method is undesirable (e.g. I'm creating a framework in PHP which emulates that from a different programming language, so ideally the method names should be the same). Test script: --- array(); class testClass { public function array() { echo("testClass::array() called."); } } ?> Expected result: testClass::array() called. Actual result: -- PHP Parse error: parse error, expecting `T_STRING' in - on line 8 -- Edit this bug report at https://bugs.php.net/bug.php?id=61275&edit=1
Bug #61275 [Dup]: Cannot have class method with same name as language construct
Edit report at https://bugs.php.net/bug.php?id=61275&edit=1 ID: 61275 User updated by: php at mralston dot com Reported by: php at mralston dot com Summary:Cannot have class method with same name as language construct Status: Duplicate Type: Bug Package:Class/Object related Operating System: Any PHP Version:5.4.0 Block user comment: N Private report: N New Comment: Fair enough. I didn't spot that bug report, but I didn't really know what to search for when I was looking. I don't quite understand from the other thread why resolving it is difficult, however as I am not intimately familiar with how PHP operates under the hood I am willing to accept that there are perfectly valid reasons beyond my understanding. I'll +1 the other bug report. :-) Thanks. Previous Comments: [2012-03-04 18:02:04] ni...@php.net This is a duplicate of https://bugs.php.net/bug.php?id=28261. See there for a discussion of why this is hard to do. ---- [2012-03-04 17:56:12] php at mralston dot com Changed package field from 'Compile Failure' to 'Class/Object related', as 'Compile Failure' is probably intended to relate to problems compiling PHP itself, rather than PHP scripts. ---------------- [2012-03-04 17:52:53] php at mralston dot com Description: It isn't possible to have a class method whose name is the same as any of the language constructs, e.g. array(), doing so creates a parse error as follows: PHP Parse error: parse error, expecting `T_STRING' in - on line 8 The error message is somewhat cryptic and confusing when it affects code which looks otherwise perfectly valid. This perhaps isn't a big deal for most people as the work around is to rename your method. It is a problem when using a different name for the method is undesirable (e.g. I'm creating a framework in PHP which emulates that from a different programming language, so ideally the method names should be the same). Test script: --- array(); class testClass { public function array() { echo("testClass::array() called."); } } ?> Expected result: testClass::array() called. Actual result: -- PHP Parse error: parse error, expecting `T_STRING' in - on line 8 -- Edit this bug report at https://bugs.php.net/bug.php?id=61275&edit=1