PHP json_encode($GLOBALS) error? the reason is simple!

Some friends will think about saving the environment variable into json, but in the end they find that there is nothing, and if you look carefully, you will find that the file is 1 byte larger. json_encode($GLOBALS) will return false for the following reasons:

Loop recursion. Print $GLOBALS, you can see in the last property:


*RECURSION*, when you try to get it, it just keeps recursively calling itself:

$ GLOBALS ['GLOBALS'] ['GLOBALS'] ['GLOBALS'] ['GLOBALS'] == $ GLOBALS :



The solution is simple:


Perfect output!


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325684498&siteId=291194637