php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46593 $object instanceof __CLASS__ is not allowed
Submitted: 2008-11-17 13:17 UTC Modified: 2008-11-17 13:22 UTC
From: jtaal at eljakim dot nl Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.2.6 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 - 24 = ?
Subscribe to this entry?

 
 [2008-11-17 13:17 UTC] jtaal at eljakim dot nl
Description:
------------
The PHP parser currently cannot handle "__CLASS__" directly after "instanceof". I think this should be possible.

Reproduce code:
---------------
class myclass {
    function mymethod($otherObject) {
        if ($otherObject instanceof __CLASS__) {
            $otherObject->mymethod(null);
        }
        return 'works!';
    }
}

$a = new myclass();
print $a->mymethod($a);

Expected result:
----------------
works!

Actual result:
--------------
Parse error: syntax error, unexpected T_CLASS_C, expecting T_STRING or T_VARIABLE or '$' in ... on line 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-17 13:22 UTC] jtaal at eljakim dot nl
I've found the solution:

$otherObject instanceof self

(maybe someone can find this issue using a searchengine)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 14:01:32 2024 UTC