Problems with JSON and PHP

Mark Moellering markmoellering at psyberation.com
Fri Feb 1 15:25:03 UTC 2019


On Fri, Feb 1, 2019 at 10:17 AM <freebsd at boosten.org> wrote:

> >> 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
>

There you go, injecting logic.  The only other thing I can think of is
check the FPM php.ini file.  What happens if you try a simple json_encode
of a string?  Try the simplest call first, then go on from there.


More information about the freebsd-questions mailing list