Home > Article > Backend Development > Reasons for errors in PHP json_encode($GLOBALS)
Some friends will think about changing the environment variables into json and saving them, but in the end they will find that there is no content. If you observe 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 attribute:
*RECURSION*, when you try to get it, you will find that it is just a continuous recursive call Self:
$GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']==$GLOBALS:
The solution is simple:
Perfect output!
The above is the detailed content of Reasons for errors in PHP json_encode($GLOBALS). For more information, please follow other related articles on the PHP Chinese website!