Recently, the original handwritten configuration file of the project has been moved to the management backend for easy configuration by others. This process uses the var_export function.
Summary:
1. According to official instructions, var_export must return legal PHP code. In other words, the code returned by var_export can be directly assigned to a variable as PHP code. This variable will obtain the same type of value as the one being var_exported, so the resource type cannot be simply copied. Therefore, when the variable of var_export is of resource type, var_export will return NULL. But var_dump will return the resource type.
//实验 $e = fopen("aa.php", "r"); var_export($e); var_dump($e);
//运行结果 NULL resource(3) of type (stream)
$c = 'guugle'; var_export($c); //直接打印出 'guugle' var_export($c, TRUE); //则无输出,返回变量表示 $d = var_export($c, TRUE); echo $d; //输出 'guugle'
$arr = array ( 1 , 2 , array ( "apple" , "banana" , "orange" )); file_put_contents("aa.php", "<?php \n return ".var_export($arr, true)."\n?>"); //注意:需要加第二个参数TRUE返回变量的表示