Published 2005-03-17 16:33:33

My new pet hate about PHP5 is currently the rather stupid warning:

"Strict Standards
: is_a(): Deprecated. Please use the instanceof operator in"

Why on earth is that in there? instance of requires that the class or interface you are testing against exists. That means loading code that may not actually be used if you are using negative testing.


That shouts out ineffeciency, and doesnt really give you and readibility or particularly major gains in terms of code doing the testing for you.

It's about the only warning that PHP4 code emits when running under E_STRICT if you disable it when loading the code.

here is the simple patch to get rid of this crazyness..
 

--- zend_builtin_functions.c 1 Feb 2005 19:05:56 -0000 1.256
+++ zend_builtin_functions.c 17 Mar 2005 08:20:42 -0000
@@ -672,7 +672,6 @@
Returns true if the object is of this class or has this class as one of its parents */
ZEND_FUNCTION(is_a)
{
- zend_error(E_STRICT, "is_a(): Deprecated. Please use the instanceof operator");
is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */



Mentioned By:
google.com : is_a(): Deprecated. Please use the instanceof operator (239 referals)
google.com : april (61 referals)
www.phpdeveloper.org : PHPDeveloper.org: PHP News, Views, and Community (51 referals)
www.phpdeveloper.org : PHPDeveloper.org: PHP News, Views, and Community... (42 referals)
google.com : is_a(): Deprecated (40 referals)
google.com : Deprecated. Please use the instanceof operator (39 referals)
google.com : march (37 referals)
google.com : Strict Standards: is_a(): Deprecated. (35 referals)
google.com : Strict Standards: is_a(): Deprecated. Please use the instanceof operator (34 referals)
google.com : Strict Standards: is_a(): Deprecated. Please use the instanceof operator in (28 referals)
google.com : is_a(): Deprecated. Please use the instanceof operator in (27 referals)
google.com : Strict Standards: is_a(): Deprecated (27 referals)
google.com : php remove warning (25 referals)
google.com : php is_a deprecated (22 referals)
google.com : "is_a(): Deprecated. Please use the instanceof operator" (20 referals)
google.com : december (20 referals)
www.planet-php.net : Planet PHP (16 referals)
php.zend.com : Zend Technologies - Weekly Summaries - Issue # 241 (15 referals)
google.com : is_a deprecated (15 referals)
google.com : Please use the instanceof operator (14 referals)

Comments

Really?
Do you really have to patch PHP to remove that "stupid craziness"?

I would prefer to use get_class() for that use. Since even using is_a() for a nonexistant class is "useless": how do you determine if an object is a class or subclass (or subclass of subclass, etc.) of some random unknown class?

And also beware, someday is_a's behavior /might/ be changed, like class_exists(), where it autoloads (if __autoload is defined) the class when an unknown class is requested.
#0 - Hendy Irawan ( Link) on 2005-03-17 18:58:30 Delete Comment
get_class not much better..
get_class is case preserving in php5, and lowercase in php4, so many kludges needed just to avoid a unnessecary message..

If is_a is really deprecieated WTF is it a E_STRICT warning and not a E_NOTICE!!!, like all other depreciated stuff. = serious lack of consistancy..

why is 'using is_a() for a nonexistant class is "useless":' - It works perfectly well..

dont get me started on the evil's of __autoload, pointless magic to help write unreadable code, at it's best..
#1 - Alan Knowles ( Link) on 2005-03-17 19:43:02 Delete Comment
Please do
The evil's of __autoload? Please do. That'll shed some light on us PHP slaves.

It would even be better if you uncover some of the most evilest PHP "features" you've known to date (no, I'm not talking /just/ about magic_quotes_gpc here).

It'd even be greater if you'd list some PHP "features-wannabe" that never made it to the PHP features list not because they're evil, but because PHP developers simply "hate it" (IMHO, like 'finally', which never got passed since PHP developers never wanted to go "the Java way")

Thanks. Your writings sure are very helpful.
#2 - Hendy Irawan ( Link) on 2005-03-18 05:35:08 Delete Comment

Add Your Comment

Follow us on