Home  >  Article  >  Backend Development  >  Reasons for errors in PHP json_encode($GLOBALS)

Reasons for errors in PHP json_encode($GLOBALS)

不言
不言Original
2018-04-18 14:57:271909browse


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn