Edit report at http://bugs.php.net/bug.php?id=53616&edit=1

 ID:                 53616
 Updated by:         [email protected]
 Reported by:        hey at lukecarrier dot me
 Summary:            T_LOGICAL_AND when declaring and() method in class
 Status:             Bogus
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Windows 7 x64
 PHP Version:        5.3.4
 Block user comment: N
 Private report:     N

 New Comment:

Very unlikely.


Previous Comments:
------------------------------------------------------------------------
[2010-12-27 17:09:34] hey at lukecarrier dot me

Rasmus, thanks for the explanation (it's an honour, by the way :)).
Given that 

this limitation is present in upstream tools, is there any chance of
this 

behaviour changing in future versions of PHP?

------------------------------------------------------------------------
[2010-12-27 16:47:35] [email protected]

Yes, logically you are right, but we are limited by what the various
lexers can 

do.  Neither yacc nor re2c is capable of contextual keyword distinction
like that.

------------------------------------------------------------------------
[2010-12-27 16:34:53] damian at damianzaremba dot co dot uk

That link explains the exception however I do not think that it should
be thrown in this case. It is clear that a function is being defined
rather than a logical comparison being performed.



In this context I believe it should have the result as expected above
and only apply logical comparisons in valid circumstances such as in an
if.



When defining this function, especially in a class it makes no sense to
restrict it based in builtins or logical operators. For example defining
function and() { echo "hi"; } would not affect if($bar === "foo" and
$foo === "bar"){} in any way.

------------------------------------------------------------------------
[2010-12-27 16:28:48] [email protected]

This is expected.



http://docs.php.net/manual/en/tokens.php

------------------------------------------------------------------------
[2010-12-27 16:26:45] hey at lukecarrier dot me

Description:
------------
When declaring a method named 'and' within a class, PHP throws a parse
error 

because the function name is interpreted as a logical operator
(T_LOGICAL_AND). 

This appears to be a bug, as it's clear in this context that the
developer is not 

attempting to perform a comparison.

Test script:
---------------
<?php



    class LogicalOperatorTest {



        public function and() {

            echo "successful!";

        }



    }



?>

Expected result:
----------------
The method LogicalOperatorTest->and() to be declared.

Actual result:
--------------
Parse error: syntax error, unexpected T_LOGICAL_AND, expecting T_STRING
in 

C:\pathto\lovely.php on line 5


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



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

Reply via email to