4 ms·
Regardless of the prior behavior, that particular behavior was not documented [1] and subject to change. I do think it is PHP's (very big) fault that the proper
by lifthrasiir 14y ago
Regardless of the prior behavior, that particular behavior was not documented [1] and subject to change. I do think it is PHP's (very big) fault that the proper documentation on various edge cases is missing, but it is a bit too much to disallow PHP to change undocumented behaviors. That said, the proper documentation is not enough (and PHP does not get this right either); it's rather a mere prerequisite.
[1] http://php.net/number-format http://php.net/number-format says the first argument expects float, and does not say what happens if it receives non-floats.
- soulclap 14y agoWell, exactly. It doesn't say what happens, so pass floats or expect the unexpected. I get your point but I don't think I have ever seen documentation anywhere that covers all of the possible 'abuse' scenarios.
- lifthrasiir 14y agoIt is possible to add a catch-all clause to the documentation. For example any non-float argument is converted to float via floatval(), or raises an error, and so on. This behavior can be made consistent across every API so that the documentation has only one place to describe it. PHP is missing this either AFAIK.
- soulclap 14y agoI agree this would be ideal. Will definitely keep this in mind when writing documentation (and code) for my own tiny open source projects. All the double and triple checking just adds so much bloat most of the time...
- dpark 14y ago> This behavior can be made consistent across every API so that the documentation has only one place to describe it. Sounds like that's what 'zend_parse_parameters' does, actually.
- josegonzalez 14y agoDocumentation is hard, thats why most of it is open source. Pretty sure you can edit the php docs online if you so chose.
- aethr 14y agoThe specific usecase the bug reporter has provided DOES raise a warning, which he has intentionally routed to /dev/null php -r 'print number_format("",0) . "\n";' PHP Warning: number_format() expects parameter 1 to be double, string given in Command line code on line 1