ID:               39003
 User updated by:  christoph at ziegenberg dot de
 Reported By:      christoph at ziegenberg dot de
 Status:           Open
 Bug Type:         Performance problem
 Operating System: WinXP SP2
 PHP Version:      5.1.6
 New Comment:

My version of the manual says this (from the example code):

    // Fatal Error: Argument 1 must be an instance of OtherClass
    $foo = new stdClass;
    $myclass->test($foo);

So I should get the error "Fatal error: Argument 1 passed to test()
must be an instance of OtherClassName, called in [...]", but I get the
error "Fatal error: Class 'OtherClassName' not found in [...]".

Of course these are both fatal errors, but the one hand I expect
another behaviour for the autoloader function as described and on the
other hand the "correct" error message would help to debug the code,
because the current error only refers to the __autoloader() function
(so you have to use debug_backtrace()/debug_print_backtrace()).


Previous Comments:
------------------------------------------------------------------------

[2006-10-01 06:07:57] judas dot iscariote at gmail dot com

if this is the expected behaviuor ( at least, not the behaviuor I
expect ;) ) it is not mentioned in the manual, so either the manual or
the engine needs to be corrected ;-)

------------------------------------------------------------------------

[2006-09-30 10:05:56] christoph at ziegenberg dot de

Description:
------------
if i check if a variable is an instance of specific class with
"instanceof" and the class i check for has not been loaded,
__autoloader() is not called (as expected).

if i do the "same" check by type hinting, the __autoloader() function
is called, which normally leads to including the required class file
and so unnecessarily consumes memory and time.

Reproduce code:
---------------
<?php
error_reporting(E_ALL);
class ClassName
{
    public $var = 'bla';
}
function test (OtherClassName $object)
{

}
function __autoload($class)
{
    print "try to load class $class";
}
$obj = new ClassName;
if (!($obj instanceof OtherClassName))
{
    echo "no instance of OtherClassName<br />";
}
test($obj);
?>

Expected result:
----------------
no instance of OtherClassName

Actual result:
--------------
no instance of OtherClassName
try to load class OtherClassName
Fatal error: Class 'OtherClassName' not found in [...] on line 7


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39003&edit=1

Reply via email to