A little background of my question.
I'm currently testing around on an old website and just moved from 5.3 to 5.6 (yes, still an old version).
With ZendFrameork 1.11 (yes, super old) as its framework.
But, I test it on different a server, on PHP 5.3, it's already setup as it's, but PHP 5.6 is on a newly installed server.
Between those 2, I tried to match its installed libraries / setting as much as I can.
I test around and I found, there's something going on when I did json_encode.
Take a look on snippet of the array below that will be json_encode,
First, this one is from PHP 5.3
array(2) { [0]=> array(10) { ["id"]=> int(139) ["original"]=> resource(612) of type (stream) ["createdAt"]=> object(DateTime)#215 (3) { ["date"]=> string(19) "2020-02-12 13:39:21" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["exfactoryDate"]=> object(DateTime)#214 (3) { ["date"]=> string(19) "2020-03-28 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["onboardDate"]=> NULL ["completed"]=> bool(false) ["units"]=> string(3) "318" ["sales"]=> string(8) "23468.42" } [1]=> array(10) { ["id"]=> int(140) ["original"]=> resource(614) of type (stream) ["createdAt"]=> object(DateTime)#212 (3) { ["date"]=> string(19) "2020-02-12 14:38:59" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["exfactoryDate"]=> object(DateTime)#211 (3) { ["date"]=> string(19) "2020-03-28 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["onboardDate"]=> NULL ["completed"]=> bool(false) ["units"]=> string(3) "124" ["sales"]=> string(8) "19796.88" } } ------------string(668) "{"orders":[{"id":139,"original":null,"createdAt":{"date":"2020-02-12 13:39:21","timezone_type":3,"timezone":"Australia\/Melbourne"},"exfactoryDate":{"date":"2020-03-28 00:00:00","timezone_type":3,"timezone":"Australia\/Melbourne"},"onboardDate":null,"completed":false,"units":"318","sales":"23468.42"},{"id":140,"original":null,"createdAt":{"date":"2020-02-12 14:38:59","timezone_type":3,"timezone":"Australia\/Melbourne"},"exfactoryDate":{"date":"2020-03-28 00:00:00","timezone_type":3,"timezone":"Australia\/Melbourne"},"onboardDate":null,"completed":false,"units":"124","sales":"19796.88"}]}"
When I do json_encode, as we can see, after a separator (dash
separator), it's a success.
But, when I want to do the same, on PHP 5.6
array(2) { [0]=> array(10) { ["id"]=> int(139) ["original"]=> resource(44) of type (stream) ["createdAt"]=> object(DateTime)#215 (3) { ["date"]=> string(26) "2020-02-12 13:39:21.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["exfactoryDate"]=> object(DateTime)#214 (3) { ["date"]=> string(26) "2020-03-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["onboardDate"]=> object(DateTime)#212 (3) { ["date"]=> string(26) "2020-05-12 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["completed"]=> bool(false) ["units"]=> string(3) "118" ["sales"]=> string(8) "21090.62" } [1]=> array(10) { ["id"]=> int(140) ["original"]=> resource(46) of type (stream) ["createdAt"]=> object(DateTime)#211 (3) { ["date"]=> string(26) "2020-02-12 14:38:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["exfactoryDate"]=> object(DateTime)#210 (3) { ["date"]=> string(26) "2020-03-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["onboardDate"]=> object(DateTime)#209 (3) { ["date"]=> string(26) "2020-05-21 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Australia/Melbourne" } ["completed"]=> bool(false) ["units"]=> string(3) "124" ["sales"]=> string(8) "19796.88" } } ------------bool(false) Type is not supported
As we can see, the json shows error and said type is not supported
.
Both of it, using exactly the same code, as shown below
$abc = $reportModel->getTotalOrders($default_post);
var_dump($abc);
echo '------------';
$abc = json_encode(array('orders' => $reportModel->getTotalOrders($default_post)));
var_dump($abc);
echo json_last_error_msg();
exit;
So, I'm wondering, is there any significant PHP changes related to json?
Why, the json_encode
is working on PHP 5.3 but not on 5.6?
I'm aware of this issue, where they said, we can only encode utf-8 thing.
But, I already tried to match its iconv setup between 5.3 server and 5.6, but still failed.
PHP 5.6
On here, I just setup its local environment, not on Master, since I don't want it affects globally on other website
So, I'm not sure, is there any special setup that I need to do in this particular case?
Do I missed some other setup that should be done on server?
PS - I'm not server guy. :)
PPS - both using linux I think, judging from its phpinfo()
Thanks for your time! :)
Edit #1 - Thanks @Phil for your link in the comment section, sorry, I forgot to mentioned that I'm also already look on that particular solution too.
But, my real question is not about omit / removing stream part, rather than, is there any specific things that I missed between PHP 5.3 and 5.6, specifically on
json_encode
function?Edit #2 - As suggested, I change some part to code rather than images.
Also, this question has been answered by @Phil on the comment section -
See the changelog on json_encode() ~ "5.5.0 When value triggers a JSON encoding error, FALSE is returned instead of partial output"
Thanks a lot for your time!
Edit #3 - As it's flagged as duplicated question, I''m adding a notes here.
If we see the question in details, it's asking a different question.
See, on this question, what I'm asking is, is there any server setup that I missed or something else that I missed when moving from php 5.3 to 5.6, example - changelog.
And yes, as @Phil (on the comment section) has said, it seems I'm not aware of the changes made on 5.5, the json_encode has changed its process.
So, it's not a duplicate, it's totally different. Just hoping that the duplication flag won't mislead the others who seeking a real answer.