Re: [PHP-DEV] is_a() versus instanceof
Johannes Schlüter wrote: On Sat, 2009-12-19 at 01:42 +0100, Johannes Mueller wrote: if($foo instanceof bar){ .. } // runs without any notification instanceof is a language construct expecting a class identifier. It doesn't complain about on-existing classes as it would need to trigger the __autoloader which might be way too much. and if(is_a($foo, bar)){ .. } // runs with an undefined constant bar notification is_a() is a function expecting a string. And this warning is unrelated to the fact that the class bar doesn't exist, but due to the way PHP treats undefined constants. Thank you for your answers, that is what I've expected. Unfortunately this is sometimes annoying when using namespaces, where you have to take care of the namespaces too. I do understand the performance impact of a more complex solution and my fault was to mix two different operations. I expected instanceof and is_a() to check if the class exists. My personal problem was, that I didn't recognized instanceof to treat the requested class as a normal string, even it is not enclosed by quotation marks. The only protective barrier in this case seems to be a skilled IDE, that helps you to avoid referencing non existant classes. Cheers Johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] is_a() versus instanceof
On Sat, 2009-12-19 at 01:42 +0100, Johannes Mueller wrote: if($foo instanceof bar){ .. } // runs without any notification instanceof is a language construct expecting a class identifier. It doesn't complain about on-existing classes as it would need to trigger the __autoloader which might be way too much. and if(is_a($foo, bar)){ .. } // runs with an undefined constant bar notification is_a() is a function expecting a string. And this warning is unrelated to the fact that the class bar doesn't exist, but due to the way PHP treats undefined constants. Behavior is expected, johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] is_a() versus instanceof
Johannes Mueller wrote: if(is_a($foo, bar)){ .. } // runs with an undefined constant bar notification I think the instanceof solution can cause problems, because you can not trigger the problem. What do you think? I think you meant: if(is_a($foo, bar)){ since is_a() takes a string as the second parameter. Does this correction then reset your expectation about instanceof? Chris -- Blog: http://blogs.oracle.com/opal Twitter: http://twitter.com/ghrd -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] is_a() versus instanceof
Johannes Schlüter schreef: On Sat, 2009-12-19 at 01:42 +0100, Johannes Mueller wrote: if($foo instanceof bar){ .. } // runs without any notification instanceof is a language construct expecting a class identifier. It doesn't complain about on-existing classes as it would need to trigger the __autoloader which might be way too much. Wouldn't it be an idea to make a setting for this ? I find it very annoying (however understandable) it doesn't complain if I make a typo.. I assume this works the same as try-catch(Exceptio $e); (note the missing 'n'); which got me fooled before. (To be sure to be understood: Create a setting which does check the class-existance; even when autoloading must be called for it) -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php