Problems with JSON and PHP

freebsd at boosten.org freebsd at boosten.org
Fri Feb 1 15:17:54 UTC 2019


>> test# more /usr/local/www/apache24/data/test.php
>> <?php
>> print "Hello world";
>> 
>> $myObj = (object) array();
>> $myObj->name = "John";
>> $myObj->age = 30;
>> $myObj->city = "New York";
>> 
>> $myJSON = json_encode($myObj);
>> 
>> echo $myJSON;
>> ?>
>> 
>> 
>> I use php and my biggest complaint is the way it handles errors.  I think
> what is happening is that your Object Definition has a syntax error but php
> is complaining about the json_encode.
> I believe (from the php.net docs) that it should be
> 
> $myObj = new stdClass();
>> $myObj->name = "John";
>> $myObj->age = 30;
>> $myObj->city = "New York";
>> 
> 

Don’t believe that’s actually the issue, since the supplied test.php works like charm for me, either in my browser (through apache) or via command line.

If it were the declaration, the command line would fail as well.

Peter



More information about the freebsd-questions mailing list