Bug #61526 [Opn->Nab]: is_subclass_of(string, string, false) always returns false
| From: | stas@php.net | Date: | Sat, 31 Mar 2012 08:04:17 +0000 |
| Subject: | Bug #61526 [Opn->Nab]: is_subclass_of(string, string, false) always returns false | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169086@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61526&edit=1
ID: 61526
Updated by: stas@php.net
Reported by: gtisza at gmail dot com
Summary: is_subclass_of(string, string, false) always returns
false
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Debian
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is expected behavior. Please see bug #55475 for more info.
Previous Comments:
------------------------------------------------------------------------
[2012-03-29 02:37:04] yohgaki@php.net
The same behavior in PHP 5.4.1RC.
Is this a doc problem or bug in PHP?
From http://php.net/manual/en/function.is-subclass-of.php
----
allow_string
Whether to call autoloader if the class doesn't exist.
----
----
5.3.9 Added allow_string parameter
5.0.3 You may also specify the object parameter as a string (the name of the
class)
----
I'm not sure, but is this a bug introduced by is_a() fix?
I didn't follow the discussion, so I hope someone could address this issue.
BTW, correct PoC would be following code.
<?php
class Super {}
class Sub extends Super {}
var_dump(is_subclass_of('Sub', 'Super')); // true
var_dump(is_subclass_of('Sub', 'Super', true)); // true
var_dump(is_subclass_of('Sub', 'Super', false)); // false
?>
------------------------------------------------------------------------
[2012-03-27 09:46:04] gtisza at gmail dot com
Description:
------------
According to the documentation ( http://php.net/manual/en/function.is-subclass-of.php
) the third parameter of is_subclass_of decides "Whether to call autoloader if the class
doesn't exist."
That means that is_subclass_of('class1', 'class2', false) should
- return true if class1 is loaded and a subclass of class2
- return false if class1 is loaded but not a subclass of class2
- return false if class1 is not loaded
What actually happens is that it always returns false, no matter what. The naming of the parameter -
"$allow_string" - suggests this is somewhat intentional, but it is a completely
unintuitive and unhelpful behavior, which makes the option completely useless: is_subclass_of with
$allow_string set to false becomes worthless if the first argument is a string, and if it is an
object, the third parameter is pointless again as the class must have been loaded already.
Test script:
---------------
class Super {}
class Sub extends Super {}
var_dump(is_subclass_of('Sub', 'Super')); // true
var_dump(is_subclass_of('Sub', 'Super'), false); // should be true but false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61526&edit=1