Reasons for errors in PHP json_encode($GLOBALS)

不言
Release: 2023-03-24 10:46:02
Original
1922 people have browsed it


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template