Live data from Hacker News

PHP Bug: #50696: number_format when passed a 0, returns null

bugs.php.net

31–40 of 51 posts

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#31
post #18

I don't see why it should return null. If "" == 0, meaning "" is coerced to 0, shouldn't it coerce to 0 here too?

While I understand (and agree with) the change to try and standardize PHP behavior, I think that in this case the parent comment is the crux of the issue. Seems like returning NULL violates the principle of least surprise to me.

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#32
post #7

A bit unrelated to the discussion... but will anyone be surprised if they get a couple of cents more (or less) on their retirement? 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 ] )"

From the documentation is correct!

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.

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#33
post #2

Interesting discussion in there, but I think the PHP guys are right on this one. You should never rely on undefined behavior of any API for mission critical code. Always use what is documented so you don't have to cry later..

This would work if programmers actually documented their code.

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. ;-)

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#34
post #32
post #7

A bit unrelated to the discussion... but will anyone be surprised if they get a couple of cents more (or less) on their retirement? 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 ] )"

From the documentation is correct! 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!

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#35
post #3

"Escalate? Oh how I wish I had someone to escalate to." Classic.

I'm going to miss Rasmus at Yahoo!. I've spent a fair amount of time with him on the road giving lectures to college students and at conferences.

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.

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#36
post #23
post #3

"Escalate? Oh how I wish I had someone to escalate to." Classic.

You know what's more depressing? This clueless guy is one of the (wild guess) 5% of PHP users who can file a bug report and follow it...

I would guess even lower. I'm not sure why that depresses you though. In my mind, that's actually a sign of success for the language.

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#37
post #19

I'm definitely on the PHP guys with this. A big criticism against PHP is that it's inconsistent in numerous ways. This bugfix is obviously part of an effort to standardize function behaviour. Go PHP!

But the problem with this is that those inconstancies have been around for so long that people have come to rely on them. So when you try to "fix the glitch", people get upset.

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...

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#38
post #4
post #3

"Escalate? Oh how I wish I had someone to escalate to." Classic.

I like his humility. Many people in these situations would be like: "Do you know who I am?"

"Do you know who I am?" is probably a better answer. The "humble" answer is just an amusing in-joke at the expense of the poster. ("Haha, look at that dumb n00b who doesn't know who Rasmus is!" There is even a comment below that pretty much says this exactly.)

"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.

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#39
Although Rasmus is quite clearly right to have fixed the undefined behaviour and is probably quite charming in person, if anyone in our company responded to one of our customers like that, well, there'd be trouble.

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.

Re: PHP Bug: #50696: number_format when passed a 0, returns null

#40

Although Rasmus is quite clearly right to have fixed the undefined behaviour and is probably quite charming in person, if anyone in our company responded to one of our customers like that, well, there'd be trouble. 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 rel…

Presumably the people in your company aren't unpaid volunteers.
Post reply on HN