|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-03-04 17:56 UTC] php at mralston dot com
-Package: Compile Failure
+Package: Class/Object related
[2012-03-04 17:56 UTC] php at mralston dot com
[2012-03-04 18:02 UTC] nikic@php.net
[2012-03-04 18:02 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2012-03-04 18:30 UTC] php at mralston dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 02:00:01 2025 UTC |
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: --------------- <?php $test=new testClass(); $test->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