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:
---------------
<?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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61275&edit=1

Reply via email to