PHP newer version fails decoding json "version like" string (ex: "0.7.4"->"0.7") -


executing code in php expect string "0.7.4" remaining "0.7.4" https://3v4l.org/gx4vm

$value = "0.7.4";  if(!empty($value)) {   $jsonvalue = json_decode($value);   if(!empty($jsonvalue)) $value = $jsonvalue; }  print_r( $value,false); 

and true every php version in aws php 5.6.9, , in php sandbox (5.6.4 ?), i'm getting 0.7 http://ideone.com/2uuohw

in code $value can deserializable string or simple string ("['a','b']", "{'a':'10'}", "abc", "2500", etc.) , expect json decode properly. have no idea how avoid strange issue.

any idea? thanks

as stated, 0.7.4 not valid json (according json spec), php's json_decode can decode scalar values, too.

php implements superset of json specified in original » rfc 4627 - encode , decode scalar types , null. rfc 4627 supports these values when nested inside array or object.

from: http://php.net/json_decode

if had $value ='"0.7.4"'; (7 characters), json_decode() decode string 0.7.4. since value 0.7.4 (5 characters, since it's missing double quotes), can't decoded.

your example @ https://3v4l.org/gx4vm failing decode $value , printing out original value (see: https://3v4l.org/e3um2).

edit: weird reason, example @ http://ideone.com/2uuohw decoding 0.7.4 float 0.7. shouldn't happen. should 0.7 if stated $value = "0.7": (see: https://3v4l.org/h2w5m).


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -