Test Code 1.php
Copy CodeThe code is as follows:
$g 1 = ' G1 ';
Class c{
function Fun () {
Include (' 2.php ');
echo "\ n-----in class fun---\ n";
Global $g 1;
Var_dump ("\ $g 1 =", $g 1
, ' $g 2 = ', $g 2
, ' $gg 2 = ', $gg 2
);
echo "\ n--------\ n";
}
}
C::fun ();
echo "\ n---in 1.php----\ n";
Var_dump (' $g 1 = ', $g 1
, ' $g 2 = ', $g 2
, ' $gg 2 = ', $gg 2);
echo "\ n-------\ n";
Code 2.php
Copy CodeThe code is as follows:
$g 2 = ' G2 ';
Global $GG 2;//This environment is not holistic and needs to be improved
$gg 2 = ' gg2 ';
function G2fun () {
Global $g 1, $g 2, $gg 2;
echo "\ n---in g2fun----\ n";
Var_dump (' $g 1 = ', $g 1, ' $g 2 = ', $g 2
, ' $gg 2 = ', $gg 2);
echo "\ n-------\ n";
}
G2fun ();
echo "\ n---in 2.php----\ n";
Var_dump (' $g 1 = ', $g 1, ' $g 2 = ', $g 2
, ' $gg 2 = ', $gg 2
);
echo "\ n-------\ n";
Global $g 1;
echo "\ n---in 2.php global----\ n";
Var_dump (' $g 1 = ', $g 1, ' $g 2 = ', $g 2
, ' $gg 2 = ', $gg 2
);
echo "\ n-------\ n";
Results
Copy CodeThe code is as follows:
---in g2fun----
String (7) "$g 1 ="
String (2) "G1"
String (7) "$g 2 ="
Null
String (8) "$gg 2 ="
String (3) "GG2"
--- ----
---in 2.php----
String (7) "$g 1 ="
Null
String (7) "$g 2 ="
String (2) "G2"
String (8) "$gg 2 ="
String (3) "GG2"
--- ----
---in 2.php global----
String (7) "$g 1 ="
String (2) "G1"
String (7) "$g 2 ="
String (2) "G2"
String (8) "$gg 2 ="
String (3) "GG2"
--- ----
-----in class Fun---
String (7) "$g 1 ="
String (2) "G1"
String (7) "$g 2 ="
String (2) "G2"
String (8) "$gg 2 ="
String (3) "GG2"
--------
---in 1.php----
String (7) "$g 1 ="
String (2) "G1"
String (7) "$g 2 ="
Null
String (8) "$gg 2 ="
String (3) "GG2"
--- ----
Thus
After the Include in class, the Include file variable domain has become a func, non-Global.
But it can be promoted through global.
Generally by the include file in the writing, may be due to the lack of attention to the case of the include, I feel a bit depressed.
http://www.bkjia.com/PHPjc/328040.html www.bkjia.com true http://www.bkjia.com/PHPjc/328040.html techarticle The code for the test code 1.php Copy code is as follows: PHP $g 1 = ' G1 '; class c{function Fun () {include (' 2.php '); echo "\ n-----in class fun---\ n"; glo Bal $G 1; Var_dump ("\ $g 1 =", $g 1, ' $g 2 ...