[DC-936] json schema import broken Created: 22/Nov/10  Updated: 22/Dec/10

Status: Open
Project: Doctrine 1
Component/s: File Parser
Affects Version/s: 1.2.3
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Mael Nison Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None
Environment:

PHP 5.3.3-1ubuntu9.1


Attachments: File foobar.schema.json    

 Description   

With a valid Json file :
PHP Warning: explode() expects parameter 2 to be string, object given in Doctrine/Doctrine/Import/Schema.php on line 381
PHP Catchable fatal error: Object of class stdClass could not be converted to string in Doctrine/Doctrine/Import/Schema.php on line 391

It's due to this line, line, in Doctrine/Parser/Json.php (#65) :
$json = json_decode($contents);

It should be:
$json = json_decode($contents, true);

Because casting the result as array will only affect the top-level element. You must use the second parameter of json_decode() to force every objects (including sub-objects) to be converted to indexed arrays.



 Comments   
Comment by Mael Nison [ 22/Nov/10 ]

A try to import this file should fail.

Comment by Brian Fenton [ 22/Dec/10 ]

I've submitted a pull request w/patch and unit test for this issue using the fix above. I had the same problem in my code on OS X 10.6.4, PHP 5.3.2

Generated at Sun Sep 21 14:10:39 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.