note 108701 added to function.json-decode

From: Date: Fri, 18 May 2012 17:54:48 +0000
Subject: note 108701 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-188061@lists.php.net to get a copy of this message
I thought I would advise you to be careful if using U.S. addresses, particularly five-digit zip codes, with json_encode and json_decode. The manual states that json_decode($data) will return $data in the appropriate PHP type. But it may not be the type you stored! In my case, I have some data that might be scalar (e.g. string containing "01234") or might be a json packet (containing multiple zipcodes), and I was calling json_decode on everything. <?php $zip = "01234"; $test_zip = json_decode($zip); echo $zip === $test_zip; // FALSE ?> Because $test_zip is an integer containing 1234. ---- Server IP: 192.41.42.26 Probable Submitter: 70.167.213.163 ---- Manual Page -- http://www.php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/108701 Del: integrated -- https://master.php.net/note/delete/108701/integrated Del: useless -- https://master.php.net/note/delete/108701/useless Del: bad code -- https://master.php.net/note/delete/108701/bad+code Del: spam -- https://master.php.net/note/delete/108701/spam Del: non-english -- https://master.php.net/note/delete/108701/non-english Del: in docs -- https://master.php.net/note/delete/108701/in+docs Del: other reasons-- https://master.php.net/note/delete/108701 Reject -- https://master.php.net/note/reject/108701 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188061) next »