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

 ID:                 55000
 User updated by:    lenar at city dot ee
 Reported by:        lenar at city dot ee
 Summary:            instanceof should fail compile-time if checking for
                     non existant class
 Status:             Bogus
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Linux
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for answering.



But I think this is really a bug. Maybe it's different mindsets but I really 
think



$a instanceof NonExistentClass



should fail as would



$a = new NonExistentClass()



Sorry, I don't see the reasoning behind 'this is expected behavior'. The

current behavior seems to be some evolutionary mishap at most, not something

an average developer would expect from instanceof operator as it easily provides

a way to shoot oneself in a leg (think simple typo). It's not really KISS.


Previous Comments:
------------------------------------------------------------------------
[2011-06-07 20:33:22] [email protected]

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. You can do something like



<?php

namespace A;



include_once('partial-namespace-a.php');



var_dump($a instanceof Test);



which can evaluate to true or false depending on the included file.

------------------------------------------------------------------------
[2011-06-06 16:13:04] lenar at city dot ee

Description:
------------
If the use clause is missing (class/interface not found in current namespace) 
trigger some fatal error.



This would catch many errors when the use clause

is just forgotten by developer.



I would understand the current behavior for those cases:



1) $a instanceof $b

2) $a instanceof 'BarClass' (not supported currently afaik)





Test script:
---------------
<?php



namespace Test;



// use FooNamespace\BarClass;



$a = new \stdClass();

var_dump($a instanceof BarClass);

Expected result:
----------------
Fatal error or at least some Exception.

Actual result:
--------------
bool(false)


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



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

Reply via email to