php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #32603 there is no easy way to check if class implements some interface
Submitted: 2005-04-06 08:56 UTC Modified: 2006-04-03 13:46 UTC
From: indeyets at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.0.4 OS:
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: indeyets at gmail dot com
New email:
PHP Version: OS:

 

 [2005-04-06 08:56 UTC] indeyets at gmail dot com
Description:
------------
there is no easy way to check if class implements some interface. This
is needed, when, for example, php-application has support for loading
external classes.

external classes have to implement some interface. And check for this
should happen BEFORE object creation. (for example, there might be a
need for some specific constructor syntax).

PHP 5.0 allows to do the following things:
1). $parent = get_parent_class("SomeClassName"). This would be
sufficient, if plugins _extend_ some base class. that's not our case -
wouldn't work for interfaces
2). if ($obj instanceof "SomeInterfaceName") {}. This would work, if we
could create object before the interface check. Wouldn't work for
non-existen objects
3). reflection API. it can do the thing, but overhead (both in code and
in resources) is too big


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-13 00:05 UTC] helly@php.net
How about: http://php.net/class-implements
 [2005-04-13 07:19 UTC] indeyets at gmail dot com
class_implements() requires object instantiaiton too. That is a step, which I need to skip.

I need to check if Class implements interface, not Object!
 [2006-04-03 13:46 UTC] tony2001@php.net
class_implements():
Parameters
class 
An object (class instance) or __a string (class name)__.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 02:01:33 2025 UTC