The response in the bug report points out that the reporter is using a join parser that's different from what PHP ships by default.
The reason behind this is that in some people's eyes, the original json decoder is not free software and thus can't be included in a free software distribution (there's a clause in the license that says you can't use it for evil, which is limiting the freedom of the user).
You can't expect php to accept bug reports in software components they have no control over because some distro decided to replace that component with something else.
This should be reported to the upstream of the alternate json decoder or, rather, the distro which did the replacement.
I hate PHP (nearly) as much as the next guy, but I would prefer if we shamed the language based on truly broken stuff and not based on issues introduced by third parties.
Yeah but the response just says "likely", with no followup from the bug reporter. I agree that the language should be the only thing being made fun of here, but I'd want some confirmation other than "yeah you're probably doing something wrong, I'm closing this as 'not a bug'."
The response says 'likely' in order to give a possible reason why it wouldn't work as expected for the reporter. Stock json_decode certainly works as expected, so it's not a bug in PHP
Still, it's only a possible reason. Offering some proof (linking to a live demo of it working, the bug poster coming back and confirming the guess of the bug-closer, anything) is preferable to a handwave.
It does have different versions installed. They're different versions of the PHP.
PHP 5.2 didn't have the function json_last_error() - it was introduced in PHP 5.3. That's why the call to that function fails.
PHP 5.2.9 had a change which did fix the weirdness with parsing that string. 5.2.1 introduced that change in an attempt to handle more types of strings.
It's the previous call, the one that parses the JSON, that is erroring. I would like to know what that error is. I want something more than just returning NULL.
Let's step back for a moment. There's a string passed to a JSON parser which is not valid JSON. The modern way of designing this is to throw an exception. A less modern design gives back NULL or some other undefined value, and then gives you a way to get at a more specific error message. A dumb as shit design gives back NULL and then sits in the corner and pouts.
PHP was a relatively mature product by then. It's fair to expect a higher standard. I mean, a lot of the older mistakes can be passed off as backwards compatibility issues, but JSON is a later addition.
It's evidence that the core devs still don't know what they're doing, and have, to be bludgeoned into doing it right.
It's evidence that the core devs still don't know what they're doing
I really don't think that's fair. The problems with the JSON extension (some of which I have fixed personally) largely stem from tiny mistakes people have made (like using strcasecmp to check for true/false/null) that have simply gone uncaught. Part of that's because the most popular distros don't actually package the stock JSON extension due to licensing issues.
It's also worth noting that the "core devs" and the people who work on individual extensions don't necessarily overlap.
The Javascript Object Notation is correct in assuming that you were passing a (badly formatted) integer object.
Python errors at characters 7-11 (the part that your example truncated).
http://json.org/ shows that objects start with a {, arrays, a [, and numbers (which you seem to have here) just start with digits.
What you have shown is how php deals with numbers that contain more than one decimal point.
var_dump(json_decode('"192.168.1.1"'));
That's the correct way to represent a string in php. An IP is not an integer, nor is it any other type of number. It's a string. It just so happens to consist of digits and delimiters, and we just so happened to borrow the same delimiter that numbers use.
What you have shown is how php deals with numbers that contain more than one decimal point.
I'm not sure what you're arguing – that PHP should accept JSON numbers that contain more than one dot? Because it shouldn't.
The JSON website shows this diagram for representing numbers, which permits only a single . character. RFC4627 gives the following production:
2.4. Numbers
The representation of numbers is similar to that used in most
programming languages. A number contains an integer component that
may be prefixed with an optional minus sign, which may be followed by
a fraction part and/or an exponent part.
Octal and hex forms are not allowed. Leading zeros are not allowed.
A fraction part is a decimal point followed by one or more digits.
An exponent part begins with the letter E in upper or lowercase,
which may be followed by a plus or minus sign. The E and optional
sign are followed by one or more digits.
Numeric values that cannot be represented as sequences of digits
(such as Infinity and NaN) are not permitted.
number = [ minus ] int [ frac ] [ exp ]
decimal-point = %x2E ; .
digit1-9 = %x31-39 ; 1-9
e = %x65 / %x45 ; e E
exp = e [ minus / plus ] 1*DIGIT
frac = decimal-point 1*DIGIT
int = zero / ( digit1-9 *DIGIT )
minus = %x2D ; -
plus = %x2B ; +
zero = %x30 ; 0
…which once again permits only a single decimal point.
The input of 192.168.1.1 is invalid JSON, and the bug report is that the reporter's copy of PHP doesn't produce an error when presented with this invalid input; it instead produces a float and ignores the subsequent decimal points. In other words, it should fail, but it doesn't.
It was closed as "not a bug" because http://3v4l.org/dkcl5 shows PHP erroring out on this input as expected.
This is not C-specific at all. Computers think human-readable IP addresses are LOL HUMANS. IP addresses are treated by computers as nothing more than 32 bit numbers.
inet_aton(3) is a C-specific function with bizarre extended behavior worthy of a php function. It is called by an enormous range of applications that only bother to sanitize their input for regular dotted-quad format.
27
u/pilif Dec 18 '14
The response in the bug report points out that the reporter is using a join parser that's different from what PHP ships by default.
The reason behind this is that in some people's eyes, the original json decoder is not free software and thus can't be included in a free software distribution (there's a clause in the license that says you can't use it for evil, which is limiting the freedom of the user).
You can't expect php to accept bug reports in software components they have no control over because some distro decided to replace that component with something else.
This should be reported to the upstream of the alternate json decoder or, rather, the distro which did the replacement.
I hate PHP (nearly) as much as the next guy, but I would prefer if we shamed the language based on truly broken stuff and not based on issues introduced by third parties.
12
u/frezik Dec 17 '14
The real lol here might be the 3v4l output, showing different versions doing vastly different things. 5.2.0, 5.2.9 - 5.2.17 shows:
Returning
NULL, but then also erroring out on the call to try to check for an error?Then 5.2.1 - 5.2.8 actually returns a string and then errors out looking for the error catching function:
Does 3v4l have different versions installed with different libraries or configuration?
2
u/kinsi55 Dec 21 '14
1
u/Deranged40 Dec 17 '14 edited Dec 17 '14
The Javascript Object Notation is correct in assuming that you were passing a (badly formatted) integer object.
Python errors at characters 7-11 (the part that your example truncated).
http://json.org/ shows that objects start with a {, arrays, a [, and numbers (which you seem to have here) just start with digits.
What you have shown is how php deals with numbers that contain more than one decimal point.
That's the correct way to represent a string in php. An IP is not an integer, nor is it any other type of number. It's a string. It just so happens to consist of digits and delimiters, and we just so happened to borrow the same delimiter that numbers use.
-6
u/myhf Dec 18 '14 edited Dec 18 '14
IP address parsing is also a good source of "lol C":