From:             
Operating system: Linux/Ubuntu
PHP version:      5.3.2
Package:          JSON related
Bug Type:         Bug
Bug description:json_decode reports no error while returning NULL

Description:
------------
I'm attempting to use json_decode on a relatively long piece of JSON. The
JSON 

is returned successfully by file_get_contents, and is valid according to 

JSONLint.



What I expect to happen is for the JSON to be correctly decoded, or NULL to
be 

returned and json_last_error to be populated with the reason. For some
reason 

NULL is returned and json_last_error remains at 0.



I have a feeling that this could be to do with the length of the file 

(containing a large array of objects).



I'm currently using:



r...@ross-laptop:/$ php -v



PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:01:00)


Copyright (c) 1997-2009 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Test script:
---------------
<?php

$raw =
file_get_contents("http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0001/?gameid=440";);



$decoded = json_decode($raw);



$errors = array(

    JSON_ERROR_NONE => "No error has occurred",

    JSON_ERROR_DEPTH => "The maximum stack depth has been exceeded",

    JSON_ERROR_CTRL_CHAR => "Control character error, possibly incorrectly
encoded",    

    JSON_ERROR_SYNTAX => "Syntax error",

    //JSON_ERROR_UTF8 => "Malformed UTF-8 characters, possibly incorrectly
encoded"

);



var_dump("Raw result:", $raw, "\n\n");

var_dump("Decoded result:", $decoded, "\n\n");

var_dump("JSON errors:", $errors[json_last_error()]);

Expected result:
----------------
Raw result: (long raw json)

Decoded result: object stdClass(1) { (data array) }

JSON errors: string "No error has occurred"

Actual result:
--------------
Raw result: (long raw json)

Decoded result: NULL

JSON errors: string "No error has occurred"

-- 
Edit bug report at http://bugs.php.net/bug.php?id=52262&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52262&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52262&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52262&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52262&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52262&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52262&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52262&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52262&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52262&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52262&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52262&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52262&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52262&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52262&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52262&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52262&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52262&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52262&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52262&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52262&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52262&r=mysqlcfg

Reply via email to