#41137 [Bgs]: is_a() for interfaces
| From: | stas@php.net | Date: | Sun, 29 Apr 2007 12:53:37 +0000 |
| Subject: | #41137 [Bgs]: is_a() for interfaces | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-112038@lists.php.net to get a copy of this message | ||
ID: 41137
Updated by: stas@php.net
Reported By: amadeusz dot jasak at gmail dot com
Status: Bogus
Bug Type: Feature/Change Request
Operating System: -
PHP Version: 5.2.1
New Comment:
I don't think reflection is really much slower than is_a - it adds a
couple of object creations, but that's it. Not sure what you mean by
"not everyone has" - what could be the reason not to have it?
Previous Comments:
------------------------------------------------------------------------
[2007-04-29 12:48:34] amadeusz dot jasak at gmail dot com
Yes, I know, but not everyone has Reflection API, reflection slow...
------------------------------------------------------------------------
[2007-04-29 12:38:19] stas@php.net
I think reflection extension allows to do such checks.
------------------------------------------------------------------------
[2007-04-19 15:18:18] amadeusz dot jasak at gmail dot com
So, maybe new function for checking interface implementation for
classes?? Like bool is_implementing(mixed $class_or_object, string
$interface)
------------------------------------------------------------------------
[2007-04-19 15:01:33] cellog@php.net
quoting the manual (http://php.net/is_a):
"bool is_a ( object $object, string $class_name )
Checks if the given object is of this class or has this class as one
of its parents."
'foo' is not an object (it is a string), and therefore is_a()
returns false.
is_a('foo', 'foo')
is also false for the same reason.
------------------------------------------------------------------------
[2007-04-19 06:31:39] amadeusz dot jasak at gmail dot com
Description:
------------
is_a function will be works if first argument is class name and next
argument is interface name. Currently it isn't working... I can't check
for class (not object) is implementing some interface
Reproduce code:
---------------
<?php
inteface factory
{
public static function _factory($params);
}
class foo implements factory
{
public static function _factory($params)
{
$t = new foo();
return $t; // Sweet use of factory ;)
}
}
var_dump
(
is_a('foo', 'factory'), // Currently return false, but true is
expected
is_a($foo = new foo(), 'factory') // It is working but it isn't
practicly
);
?>
Expected result:
----------------
bool(true)
bool(true)
Actual result:
--------------
bool(false)
bool(true)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41137&edit=1