Edit report at https://bugs.php.net/bug.php?id=61526&edit=1

 ID:                 61526
 Updated by:         yohg...@php.net
 Reported by:        gtisza at gmail dot com
 Summary:            is_subclass_of(string, string, false) always returns
                     false
 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:

I committed doc improvement.


Previous Comments:
------------------------------------------------------------------------
[2012-03-31 08:29:09] yohg...@php.net

Automatic comment from SVN on behalf of yohgaki
Revision: http://svn.php.net/viewvc/?view=revision&revision=324657
Log: Fix #61526 Improve doc.

------------------------------------------------------------------------
[2012-03-31 08:04:17] s...@php.net

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.

------------------------------------------------------------------------
[2012-03-29 02:37:04] yohg...@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

Reply via email to