PHP Bug: #50696: number_format when passed a 0, returns null
bugs.php.net
bugs.php.net
Always use what is documented so you don't have to cry later..
Different 'bug', similar theme: I'd be v. interested to hear what HN folks think about http://bugs.php.net/bug.php?id=47494. I explained the problem here: http://insomanic.me.uk/post/191397106/php-htmlspecialchars-h...
Summary: PHP 5.3 introduces a scenario where:
display_errors=off, log_errors=on => warning msg is logged (but not displayed, of course..)
display_errors=on => NO warning is logged OR displayed(?!)
Took me ages to figure out, that one did..My vote for the other side is because php guys didn't document the change. Other pages show exactly what happens in strange cases - like in "If delimiter is an empty string (""), explode() will return FALSE." There's no mention about the change on http://php.net/manual/en/function.number-format.php and they list the result as "string" without any other notes. Making the function backwards compatible wouldn't hurt anyone either, because it would restore the behaviour for people using "" and would change nothing for ones using normal values all the time and ones who started casting to a number because of this change. But yes - it's pretty much php guys' call.
Anyway, saying they wouldn't fix it is fine, but the bitchy answers he got to legitimate questions just shows how juvenile R is.
Answered in the 2nd comment from Rasmus:
If this was changed in a minor version, I'd agree with you on the BC change, but we have been working on catching these weird edge-case scenarios that lead to unexpected bugs.
i.e. they thought about it and decided this version was an acceptable one for making breaking changes.
I remember posting similar sentiments on Reddit about 3 years ago and getting downmodded to oblivion. In hindsight, I think I was wrong and the herd was right. If you restrict yourself to what's documented, you'll miss out on most of the interesting and cutting-edge stuff. And that's what lets you build a cool, differentiated, useful project.
Instead, I think you should budget time and money for crying later. ;-)
Classic.
"I'm the creator of PHP. I am not going to fix this," would have ended the discussion much sooner and with less hurt feelings.
This clueless guy is one of the (wild guess) 5% of PHP users who can file a bug report and follow it...
This is one of the reasons he's such a great leader. He's got a sense of humour, but he still explains it to you no matter what. Good guy.
"I'm not a real programmer. I throw together things until it works then I move on. "
Go PHP!
So, when you say it's part of an effort to standardize behavior, I think you're right. But is this the right way to go? I mean, was the old behavior that bad? Why not just flag it as a warning and mark it as deprecated functionality? Then wait until version 6 to actually force the change.
I don't have a horse in this race, since I stopped using PHP when 5 was just coming out. One of those reasons was to avoid stuff like this...
Further I agree with what Rasmus states as one of his last remarks in that bug thread: "Wow, a classic case of how not to treat unpaid volunteers who provide critical pieces of your money-making infrastructure."
In other words, go make yourself a programming language if you have a big mouth towards volunteers when you scheme of making money with their system fails you, the bloody arrogance.
A lesson to all who rely on edge cases and un-documented behaviors for functionality.
It should thrown an exception and abort the script with an ugly error traceback.
If the documentation says "float" and you can hand it a numerical string, then either the function or its documentation have a bug that needs correcting.
I would go as far as recommend using a USB shock device to issue a warning to the programmer every times a mistake like this is made. ;-)
From the report: "Each of those changes will have to be coded, tested, written-off, released, tested by the clients since this is tax data and has to be precise for tax planning and retirement planning."
From the documentation: "string number_format ( float $number [, int $decimals ] )"
Passing a string instead of a float and expecting it to behave a certain way is undocumented. Oh my! Relying on undocumented behavior... a simple duh in the production world.
I'm not adding to the conversation, and I realize this. But simply my $0.02.
But simply my $NULL.
Oops!He could've saved himself a lot of grief if his first reply had been:
Hi,
I'm sorry to hear this change has broken your existing code. We've been cleaning up undefined behaviours such as the one you're relying on in this release and this particular fix has been reviewed and accepted by the community over a 3 month period, so there's no chance to revert it now.
Going forward, you can either patch your code to stop relying on the undocumented behaviour (e.g. cast the string to a float) or you're also free to modify the PHP source to return to the previous behaviour - one of the benefits of relying on an open source framework.
Best regards, Rasmus Lerdorf, creator of PHP
Sadly, this would never have appeared on HN and thus brightend up my Monday morning.
Some might say "PHP developer"
That point, rhetoric aside, is that the reporter is not party to a commercial contract with the people who fix bugs in PHP, whoever they might happen to be. Consequently, there should not be the "trouble" that moconnor asserted would occur should anyone in his organisation respond to a customer in that manner. The two parties simply do not have that relationship.
The phrase "unpaid volunteer" comes from Rasmus himself, in the bug report under discussion: "Wow, a classic case of how not to treat unpaid volunteers who provide critical pieces of your money-making infrastructure."
in his make up world that makes it too dificult to fix his code, he would have to go trhu 7 levels of testing hell... so why not apply it to the platform?
It seems to me that the entire process of testing and writing off is just as important when changing the target platform as it is when changing some of the API calls.
If they write tax software and don't do any formal testing, I'd seriously hesitate to use their product.
If "" == 0, meaning "" is coerced to 0, shouldn't it coerce to 0 here too?