Edit report at https://bugs.php.net/bug.php?id=55475&edit=1
ID: 55475
Updated by: dmitry@php.net
Reported by: mads at gartneriet dot dk
Summary: is_a() triggers autoloader
Status: Assigned
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.3.7
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
Before the patch, is_a() didn't accept string as the first argument at all, so it always
returned "false" and never triggered __autoload(). The proposed patch didn't revert
to original behavior. It just disables autoloading and may lead to wrong result.
class a {}
class b extends a {}
var_dump(is_a("b", "a")); // it was false before 5.3.7, now it's true
I would say that the old behaviour was wrong, especially because "instanceof" and
is_subclass_of() already implemented support for string arguments.
Previous Comments:
------------------------------------------------------------------------
[2011-08-22 10:30:19] kalle@php.net
The following patch has been added/updated:
Patch Name: bug55475
Revision: 1314009019
URL: https://bugs.php.net/patch-display.php?bug=55475&patch=bug55475&revision=1314009019
------------------------------------------------------------------------
[2011-08-22 10:29:51] kalle@php.net
Zeev, although the functionality might appear as it should be then we should not make sudden changes
like that in the middle of a stable branch, we should patch up 5.3 and keep the behaviour in 5.4 if
its indeed intended atleast to comply with previous versions.
The fix for 5.3 is simple, attached
------------------------------------------------------------------------
[2011-08-22 10:12:48] zeev@php.net
Discussed with Dmitry, the current functionality appears to be correct.
is_a('foo', 'bar') *can* be true even if class foo isn't loaded, and
we'll only
know that if we try to load 'foo'.
This is different from is_a($obj, 'non_existent_class'), which we can resolve as
'false' in case non_existent_class isn't loaded without trying to load it (there
can't be an instance of a class that doesn't exist).
------------------------------------------------------------------------
[2011-08-22 09:15:23] colder@php.net
1) The underlying implementation is shared between is_a and is_subclass_of.
2) Previously, strings as first argument was not permitted by is_a but
was for is_subclass_of,
3) is_subclass_of always triggered autoload in such cases.
4) Following a fix from Dmitry, the underlying implementation now
allows a string as first argument for is_a as well.
Conclusion: it is now consistent, but if you wrongly used is_a with a
string before, it now triggers autoload because it actually accepts
it.
------------------------------------------------------------------------
[2011-08-22 08:57:32] konstantin dot leboev at gmail dot com
I guess it's not a bug. The first argument can be a class name, what will be
loaded only on calling this function.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=55475
--
Edit this bug report at https://bugs.php.net/bug.php?id=55475&edit=1