Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.21.0

Request #11404 gettype on typeHints=true may lead to inconsistence in future PHP versions
Submitted: 2007-06-22 15:44 UTC
From: japanitrat Assigned: ashnazg
Status: Wont fix Package: XML_Serializer (version 0.18.0)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 35 + 18 = ?

 
 [2007-06-22 15:44 UTC] japanitrat (Cid O'neir)
Description: ------------ since i am developing a Flash ActionScript2 Version of the XML_Serializer, i browsed the source of 0.18.0 a bit. Especially the _type attribute must be remapped in Flash, because naming conventions are not the same. i found, that you were using the gettype() function in PHP to resolve the types. when i was looking in the php-manual, which types are possibly returned, i noticed the big red warning: ---------- Never use gettype() to test for a certain type, since the returned string may be subject to change in a future version. In addition, it is slow too, as it involves string comparison. Instead, use the is_* functions. ---------- Besides the fact that my Flash-Implementation could walk into trouble, PHP-only use of the XML_Serializer may also lead to invalid types, if those type-returns are changed in future PHP-Versions. imagine a possible PHP6 release returns "float" instead of "double" or something like that. This means, a PHP Version before these type-changes cannot resolve those types. Expected result: ---------------- you may really change this and use the is_* functions to make the types constant. Of course, those constants should be equal to the current type-names as in the php-manual: Possibles values for the returned string are: * "boolean" (since PHP 4) * "integer" * "double" (for historical reasons "double" is returned in case of a float, and not simply "float") * "string" * "array" * "object" * "resource" (since PHP 4) * "NULL" (since PHP 4) * "user function" (PHP 3 only, deprecated) * "unknown type"

Comments

 [2008-09-19 20:20 UTC] ashnazg (Chuck Burgess)
Actually, gettype() usage in XML_Serializer should be reasonably safe, since it only uses gettype() to fetch a string and use the string, no matter what it is. That warning in the manual seems to be geared towards usage like "if (gettype($foo) == 'double')", when like you say PHP6 might start returning 'float'. So, I don't a code change here will be necessary. A good point to ponder though, so thanks for highlighting it.