php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41072 Make instanceof work without the need of creating the object first
Submitted: 2007-04-13 00:49 UTC Modified: 2013-02-17 13:32 UTC
Votes:2
Avg. Score:2.5 ± 1.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: atomo64 at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.2.1 OS: Linux 2.6.18 SMP i686
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: atomo64 at gmail dot com
New email:
PHP Version: OS:

 

 [2007-04-13 00:49 UTC] atomo64 at gmail dot com
Description:
------------
At the moment instanceof requires the first 'parameter' to be an object of the class which is to be compared.
It would be useful to be able to check without creating the object.

Reproduce code:
---------------
<?php
class MyClass {}

$class = 'MyClass';

var_dump($class instanceof MyClass);
var_dump($$class instanceof MyClass);
var_dump(MyClass instanceof MyClass);
?>

Expected result:
----------------
bool(false)
bool(true)
bool(true)

Actual result:
--------------
bool(false)
bool(false)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-29 12:07 UTC] stas@php.net
I'd suggest you use reflection for this:
http://www.php.net/reflection
 [2013-02-17 13:32 UTC] nikic@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2013-02-17 13:32 UTC] nikic@php.net
You should be able to check this with the is_subclass_of function.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 26 15:01:30 2024 UTC