php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80598 Instanceof does not evaluate expressions in second operand
Submitted: 2021-01-06 12:45 UTC Modified: 2021-01-06 13:40 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: hello at rapliandras dot hu Assigned: cmb (profile)
Status: Not a bug Package: Compile Failure
PHP Version: 7.4.13 OS: Ubuntu 20
Private report: No CVE-ID: None
 [2021-01-06 12:45 UTC] 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 '('


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-06 13:05 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-01-06 13:05 UTC] 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 13:32 UTC] nikic@php.net
@cmb: instanceof also accepts a class name string, and this syntax does work as of PHP 8.0.
 [2021-01-06 13:40 UTC] cmb@php.net
@nikic, ah, indeed; that's not documented in the manual proper,
though, but since it has an item on the issues tracker, I think
this ticket can be kept closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 17:01:29 2024 UTC