Test code 1.php? Php $ g1g1; classc {functionfun () {include (2.php); echon ----- inclassfun --- n; global $ g1; var_dump ($ g1, $ g1, $ g2, $ g2, $ g2, $ gg2, $ gg2); echon -------- n ;}} c: fun (); echon --- in1.php ---- n; var_dump ($ g1,
Test code 1.php? Php $ g1 = 'g1'; class c {function fun () {include ('2. php '); echo \ n ----- in class fun --- \ n; global $ g1; var_dump (\ $ g1 =, $ g1,' $ g2 = ', $ g2, '$ gg2 =', $ gg2); echo \ n -------- \ n ;}} c: fun (); echo \ n --- in 1.php ---- \ n; var_dump ('$ g1 = ',
Test code 1.php
", $g1,'$g2 => ', $g2 ,'$gg2 => ', $gg2);echo "\n--------\n";}}c::fun();echo "\n--- in 1.php ----\n";var_dump('$g1 => ', $g1,'$g2 => ', $g2 ,'$gg2 => ', $gg2);echo "\n--- ----\n";
Code 2.php
', $ G1,' $ g2 => ', $ g2,' $ gg2 => ', $ gg2); echo "\ n --- ---- \ n ";} g2fun (); echo "\ n --- in 2.php ---- \ n"; var_dump ('$ g1 =>', $ g1, '$ g2 =>', $ g2, '$ gg2 =>', $ gg2); echo "\ n --- ---- \ n"; global $ g1; echo "\ n --- in 2.php global ---- \ n "; var_dump ('$ g1 =>', $ g1, '$ g2 =>', $ g2, '$ gg2 =>', $ gg2 ); echo "\ n --- ---- \ n ";
Result
--- in g2fun ----string(7) "$g1 => "string(2) "g1"string(7) "$g2 => "NULLstring(8) "$gg2 => "string(3) "gg2"--- ------- in 2.php ----string(7) "$g1 => "NULLstring(7) "$g2 => "string(2) "g2"string(8) "$gg2 => "string(3) "gg2"--- ------- in 2.php global----string(7) "$g1 => "string(2) "g1"string(7) "$g2 => "string(2) "g2"string(8) "$gg2 => "string(3) "gg2"--- ---------in class fun---string(7) "$g1 => "string(2) "g1"string(7) "$g2 => "string(2) "g2"string(8) "$gg2 => "string(3) "gg2"----------- in 1.php ----string(7) "$g1 => "string(2) "g1"string(7) "$g2 => "NULLstring(8) "$gg2 => "string(3) "gg2"--- ----
As you can see,
After the class is included, the variable fields in the include file have become func, not global.
But it can be upgraded through global.
When the include file is compiled, it may feel a little depressed because you have not noticed the include file.