Parsing JSON (sent via POST) from a global object in PHP
<p>I'm an average PHP programmer and I've recently built an API that accepts incoming JSON (via POST) data.  I'm using this code to parse the incoming JSON into a global object:</p>

<pre><code>$GLOBALS[json] = file_get_contents("php://input");
$GLOBALS[json] = json_decode($GLOBALS[json]);
</code></pre>

<p>That part is working perfectly fine and the value of <code>$GLOBALS[json]</code> is (from the system log):</p>

<pre><code>{
   "name": "John Doe",
   "state": "DE",
   "zip": "12345"
}
</code></pre>

<p>This global object is then being used by a function (in an included external PHP file) to read the individual pieces of the array:</p>

<pre><code>$name  = $GLOBALS[json]-&gt;name;
$state = $GLOBALS[json]-&gt;state;
$zip   = $GLOBALS[json]-&gt;zip;
</code></pre>

<p>The problem that I'm having is that none of these variables (listed directly above) have any data.  I've tried every example I can find online with no luck.</p>

<p>FYI - I've also tried using the <code>true</code> option on the end of the <code>json_decode</code> function and tried reading it as an array (instead of an object), and still no luck.</p>

<p>Is it giving me issues because I'm starting with a global object/array or am I simply trying to recall the key pair/object values incorrectly?</p>