@@ -38,25 +38,34 @@ public function handle()
3838
3939 protected function varExport ($ var , $ indent = ' ' )
4040 {
41- switch (gettype ($ var )) {
42- case 'string ' :
43- return '" ' . addcslashes ($ var , "\\\$\"\r\n\t\v\f" ) . '" ' ;
44- case 'array ' :
45- $ indexed = array_keys ($ var ) === range (0 , count ($ var ) - 1 );
46- $ r = [];
47- foreach ($ var as $ key => $ value ) {
48- $ r [] = "$ indent "
49- . ($ indexed ? '' : $ this ->varExport ($ key ) . ' => ' )
50- . $ this ->varExport ($ value , "$ indent " );
41+ if (is_array ($ var )) {
42+ $ r = [];
43+ foreach ($ var as $ item ) {
44+ if (is_object ($ item )) {
45+ $ item = (array ) $ item ; // 转换对象为数组
5146 }
52- return "[ \n" . implode (", \n" , $ r ) . "\n$ indent] " ;
53- case 'boolean ' :
54- return $ var ? 'true ' : 'false ' ;
55- case 'integer ' :
56- case 'double ' :
57- return $ var ;
58- default :
59- return var_export ($ var , true );
47+ $ itemParts = [];
48+ foreach ($ item as $ key => $ value ) {
49+ if (is_string ($ value )) {
50+ $ value = '" ' . addcslashes ($ value , "\\\$\"\r\n\t\v\f" ) . '" ' ;
51+ } elseif (is_bool ($ value )) {
52+ $ value = $ value ? 'true ' : 'false ' ;
53+ } elseif ($ value === null ) {
54+ $ value = 'null ' ;
55+ }
56+ $ itemParts [] = "' $ key' => $ value " ;
57+ }
58+ $ r [] = "$ indent [ " . implode (", " , $ itemParts ) . "] " ;
59+ }
60+ return "[ \n" . implode (", \n" , $ r ) . "\n$ indent] " ;
61+ } elseif (is_string ($ var )) {
62+ return '" ' . addcslashes ($ var , "\\\$\"\r\n\t\v\f" ) . '" ' ;
63+ } elseif (is_bool ($ var )) {
64+ return $ var ? 'true ' : 'false ' ;
65+ } elseif ($ var === null ) {
66+ return 'null ' ;
67+ } else {
68+ return $ var ;
6069 }
6170 }
6271}
0 commit comments