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
 [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

Pull Requests

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: Sat Dec 21 13:01:31 2024 UTC