|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-12-27 16:26 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 06:00:01 2025 UTC |
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.