|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62089 instanceof operator type variable from function
Submitted: 2012-05-21 09:56 UTC Modified: -
From: php dot net at kingsquare dot nl Assigned:
Status: Open Package: *General Issues
PHP Version: Irrelevant OS: n/a
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 — but make sure to vote on the bug!
Your email address:
Solve the problem:
18 + 1 = ?
Subscribe to this entry?

 [2012-05-21 09:56 UTC] php dot net at kingsquare dot nl
This might be a 'feature request', a bug or just a documentation issue..

We can use the instanceof operator using variables:
$objectType = 'StdClass'
$this instanceof $objectType

works flawlessly!

But in order to prevent introducing a variable needed just because of the check 
i would have guessed i could be able to do:

$this instanceof get_class($this)

(ofcourse the actual usage would be something else, this is just to illustrate 
the usage of a function to retrieve some type of class name)

Test script:
class Foo {
	function getClass() {
		return __CLASS__;

$bar = new Foo();

var_dump($bar instanceof $bar->getClass());

Expected result:

Actual result:
Parse error: syntax error, unexpected '('


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 05:01:26 2019 UTC