Bug #80598 [Nab]: Instanceof does not evaluate expressions in second operand
Edit report at https://bugs.php.net/bug.php?id=80598&edit=1
ID: 80598
Updated by: nikic@php.net
Reported by: hello at rapliandras dot hu
Summary: Instanceof does not evaluate expressions in second
operand
Status: Not a bug
Type: Bug
Package: Compile Failure
Operating System: Ubuntu 20
PHP Version: 7.4.13
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
@cmb: instanceof also accepts a class name string, and this syntax does work as of PHP 8.0.
Previous Comments:
------------------------------------------------------------------------
[2021-01-06 13:05:03] cmb@php.net
The right hand side of instanceof expects a class or interface
name or an object, but not a string. You cannot store a class or
interface name or an object in a class constant, so your code
makes no sense.
[1] <https://www.php.net/manual/en/language.operators.type.php>
------------------------------------------------------------------------
[2021-01-06 12:45:23] hello at rapliandras dot hu
Description:
------------
Trying the following expression:
$entity instanceof (static::BASE_CLASS)
I get PHP Parse error: syntax error, unexpected '('
Test script:
---------------
$entity instanceof (static::BASE_CLASS)
Expected result:
----------------
Even if this is on purpose, or documented, it's not the expected, intuitive behavior.
instanceof operator should have no problems with evaluating the right operand
Actual result:
--------------
PHP Parse error: syntax error, unexpected '('
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80598&edit=1
Thread (4 messages)