I don't agree with your analogy. The question is more similar to "Can you please tell me the number format of <silence>".
How can the answer to an unfinished question be "0"? 0 is an actual valid answer, when people are asking for number_format(0, 0).
In this case, NULL is definitely more appropriate, because the input is invalid.
> he question is more similar to "Can you please tell me the number format of <silence>".
Well in PHP, the number for <silence> is 0, so it would stand to reason that the formatted number for <silence> is 0 as well.
Of course, in a more sane language, it would throw an exception, rather than silently returning a wrong value.
What's the numeric representation of the volume of <silence>? 0 dB
Since dB are a log scale, more properly, it would be -Inf dB.
0 dB = atmospheric pressure. -Inf dB = vacuum of space.
So you make up a different question to fit the answer you want? Actually that seems about right for PHP.
Re:We will try to stop fixing bugs in PHP
by felipellrocha on Friday June 22, 2012 @12:32AM
(#4145416)
I think you missed the point here. Steve's analogy asks for a number format, not a volume...
Downvoted for cleverness.
I agree with Steve. "No apples" actually is "0 apples".
Your analogy is a misunderstanding of null. Null is like you asking me how many apples Joe has. I say I don't know. If you write down 0, I'm going to stop you and say, "I didn't say zero, I said I don't know."
BOTH behaviors don't make sense. The right behavior is to throw an exception.
Absolutely agree, and that's PHP's biggest issue. It is constantly doing things like this instead of simply complaining and stopping things down like any sane system would.
If I were in charge of PHP, release 6 would be 5.4.4 with the standard library happily throwing exceptions on invalid input. That's it. The language would be 100% more useful instantly.
As mentioned to parent: then you'd have a lot of work to do to clean up one even more widely used language : )
You mean JavaScript, right? Reading this conversation I was wondering how no comment would point at the same or bigger similar issues in JavaScript.
This depends on language. Or you'd have to dismiss at least on widely used systems programming language as well. : )
Well...if we are allowed to change language completely we could change to a type safe language (as most systems programming are) and we wouldn't have this discussion in the first place since it would be impossible to call the function with a string parameter...
I tell you that you have "foo" apples. Write the number of apples you have on a piece of paper. What did you write?
I tell you you have 12/0 apples. Write the number of apples you have on a piece of paper. Some "functions" are not defined for all inputs. Better to give a "that doesn't make sense" answer than a bogus answer.
I tell you that you have no apples. Write the number of apples you have on a piece of paper. What did you write? I bet it was 0, not some arbitrary, non-writable symbol for an abstract concept that could mean "nothing" or "error" or "empty" or ..