Bug #55475 [Com]: is_a() triggers autoloader
| From: | zeev@php.net | Date: | Mon, 22 Aug 2011 10:12:48 +0000 |
| Subject: | Bug #55475 [Com]: is_a() triggers autoloader | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-162766@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55475&edit=1
ID: 55475
Comment by: zeev@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:
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).
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2011-08-22 08:19:04] pajoye@php.net
Related to change for the #53727 fix.
http://svn.php.net/viewvc/php/php-
src/branches/PHP_5_3/Zend/zend_builtin_functions.c?r1=307522&r2=312904
Assigned to Dmitry
------------------------------------------------------------------------
[2011-08-22 08:16:02] mads at gartneriet dot dk
Description:
------------
When calling is_a() with a first argument that is not an object, then __autoload() is triggered:
Test script:
---------------
<?php
function __autoload($class) {
echo "Would load: " . $class . PHP_EOL;
}
$var = "test";
var_dump(is_a($var, 'B'));
$obj = new Stdclass;
var_dump(is_a($obj, 'C'));
?>
Expected result:
----------------
bool(false)
bool(false)
Actual result:
--------------
Would load: test
bool(false)
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55475&edit=1