rfc:comparison_inconsistency
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | rfc:comparison_inconsistency [2013/11/10 22:40] – [Function/Method] yohgaki | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== PHP RFC: Existing comparison and conversion inconsistency | ||
+ | * Version: 0.1 | ||
+ | * Date: 2013-10-31 | ||
+ | * Author: Yasuo Ohgaki < | ||
+ | * Status: Draft (or Under Discussion or Accepted or Declined) | ||
+ | * First Published at: http:// | ||
+ | |||
+ | This RFC is to discuss comparison and conversion inconsistencies in PHP. | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | There are number of in comparison and conversion inconsistencies. | ||
+ | |||
+ | For example, | ||
+ | * https:// | ||
+ | |||
+ | There are number issues of like this. | ||
+ | |||
+ | Purpose of this RFC is fix inconsistency where it's feasible, otherwise document then fully if it's not documented already. | ||
+ | |||
+ | ===== Inconsistency ===== | ||
+ | ==== Conversion/ | ||
+ | |||
+ | Type juggling only works for INTEGER or HEX like strings. | ||
+ | |||
+ | === HEX === | ||
+ | Code | ||
+ | var_dump(0x0A); | ||
+ | var_dump(" | ||
+ | var_dump((int)" | ||
+ | var_dump((float)" | ||
+ | var_dump(intval(" | ||
+ | var_dump(floatval(" | ||
+ | |||
+ | Output | ||
+ | int(10) | ||
+ | string(4) " | ||
+ | int(0) | ||
+ | float(0) | ||
+ | int(0) | ||
+ | float(0) | ||
+ | |||
+ | Code | ||
+ | if (0x0A == ' | ||
+ | echo "0x0A == ' | ||
+ | } | ||
+ | if (0x0A == " | ||
+ | echo '0x0A == " | ||
+ | } | ||
+ | |||
+ | Output | ||
+ | 0x0A == ' | ||
+ | 0x0A == " | ||
+ | |||
+ | |||
+ | === Octal === | ||
+ | |||
+ | Code | ||
+ | var_dump(010); | ||
+ | var_dump(" | ||
+ | var_dump((int)" | ||
+ | var_dump((float)" | ||
+ | var_dump(intval(" | ||
+ | var_dump(floatval(" | ||
+ | |||
+ | Output | ||
+ | int(8) | ||
+ | string(3) " | ||
+ | int(10) | ||
+ | float(10) | ||
+ | int(10) | ||
+ | float(10) | ||
+ | |||
+ | CODE | ||
+ | if (010 == ' | ||
+ | echo "010 == ' | ||
+ | } | ||
+ | if (010 == " | ||
+ | echo '010 == " | ||
+ | } | ||
+ | |||
+ | OUTPUT | ||
+ | (NONE) | ||
+ | |||
+ | |||
+ | === BINARY === | ||
+ | |||
+ | Code | ||
+ | var_dump(0b110); | ||
+ | var_dump(" | ||
+ | var_dump((int)" | ||
+ | var_dump((float)" | ||
+ | var_dump(intval(" | ||
+ | var_dump(floatval(" | ||
+ | |||
+ | Output | ||
+ | int(6) | ||
+ | string(5) " | ||
+ | int(0) | ||
+ | float(0) | ||
+ | int(0) | ||
+ | float(0) | ||
+ | |||
+ | CODE | ||
+ | if (0b010 == ' | ||
+ | echo "0b010 == ' | ||
+ | } | ||
+ | if (0b010 == " | ||
+ | echo '010 == " | ||
+ | } | ||
+ | |||
+ | OUTPUT | ||
+ | (NONE) | ||
+ | |||
+ | ==== Function/ | ||
+ | |||
+ | === min() function === | ||
+ | |||
+ | https:// | ||
+ | |||
+ | This is not a bug. If one of operand is BOOL(or NULL), both operands are converted to BOOL and evaluated as BOOL. It may be good idea that document this behavior in min() manual. | ||
+ | |||
+ | === Return value of wrong internal function/ | ||
+ | |||
+ | If not all, almost all functions return NULL when required function parameter is missing or wrong type. However, almost all functions return FALSE when they have errors. | ||
+ | |||
+ | The manual has document for this behavior | ||
+ | http:// | ||
+ | |||
+ | Note: If the parameters given to a function are not what it expects, such as passing an array | ||
+ | where a string is expected, the return value of the function is undefined. In this case it will | ||
+ | likely return NULL but this is just a convention, and cannot be relied upon. | ||
+ | |||
+ | This behavior could be cause of bug in scripts. For instance, | ||
+ | |||
+ | if (FALSE === some_func($wrong_parameter)) { | ||
+ | // Error happend! | ||
+ | } else { | ||
+ | // OK to go | ||
+ | } | ||
+ | |||
+ | Users should not rely on return value as it may return NULL for wrong parameters. Users should rely on error/ | ||
+ | |||
+ | It may be good to add use of error/ | ||
+ | http:// | ||
+ | |||
+ | There are bug reports that complain return value inconsistency. The document could be improved with more explanations. | ||
+ | |||
+ | == Related Bug Reports == | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | Bug reports are not verified carefully. Removing wrong one, adding proper one is appreciated. | ||
+ | |||
+ | == Developer Guideline == | ||
+ | |||
+ | * Internal function/ | ||
+ | * Internal function/ | ||
+ | * Internal function/ | ||
+ | |||
+ | == User Guideline == | ||
+ | |||
+ | * User should not rely return value only for failure condition, but should rely error/ | ||
+ | |||
+ | ===== Proposal ===== | ||
+ | |||
+ | Not yet. | ||
+ | |||
+ | ===== Backward Incompatible Changes ===== | ||
+ | |||
+ | Not yet. | ||
+ | |||
+ | ===== Proposed PHP Version(s) ===== | ||
+ | |||
+ | PHP 6.0 probably. | ||
+ | |||
+ | ===== Impact to Existing Extensions ===== | ||
+ | |||
+ | Not yet. | ||
+ | |||
+ | ===== New Constants ===== | ||
+ | |||
+ | Not yet. | ||
+ | |||
+ | ===== php.ini Defaults ===== | ||
+ | |||
+ | If there are any php.ini settings then list: | ||
+ | * hardcoded default values | ||
+ | * php.ini-development values | ||
+ | * php.ini-production values | ||
+ | |||
+ | Not yet. | ||
+ | |||
+ | ===== Open Issues ===== | ||
+ | |||
+ | Make sure there are no open issues when the vote starts! | ||
+ | |||
+ | ===== Unaffected PHP Functionality ===== | ||
+ | |||
+ | List existing areas/ | ||
+ | |||
+ | This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise. | ||
+ | |||
+ | ===== Future Scope ===== | ||
+ | |||
+ | This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC. | ||
+ | |||
+ | ===== Proposed Voting Choices ===== | ||
+ | |||
+ | Include these so readers know where you are heading and can discuss the proposed voting options. | ||
+ | |||
+ | ===== Patches and Tests ===== | ||
+ | |||
+ | Links to any external patches and tests go here. | ||
+ | |||
+ | If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed. | ||
+ | |||
+ | Make it clear if the patch is intended to be the final patch, or is just a prototype. | ||
+ | |||
+ | ===== Implementation ===== | ||
+ | |||
+ | After the project is implemented, | ||
+ | - the version(s) it was merged to | ||
+ | - a link to the git commit(s) | ||
+ | - a link to the PHP manual entry for the feature | ||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | Links to external references, discussions or RFCs | ||
+ | |||
+ | ===== Rejected Features ===== | ||
+ | |||
+ | Keep this updated with features that were discussed on the mail lists. | ||
+ | |||
+ | ===== ChangeLog ===== | ||
+ | |||
+ | * 2013/10/31 - Initial version. |