There are strict variable scopes in java, c, and c, while php does not have a clear (inaccurate) scope, for example, a variable defined outside a method-a method that cannot be referenced in the method can solve this problem by using a magic function or a global function such as the super global variable requestsessionpost, with the focus on global! A common PHP file, such
There are strict variable scopes in java, c, and c, while php does not have a clear (inaccurate) scope, for example, a variable defined outside a method-a method that cannot be referenced in the method can solve this problem by using a magic function or global such as the super global variable request session post, with the focus on global! A common PHP file, such
There are strict variable scopes in java, c, and c ++, while php does not have a clear (inaccurate) scope, for example, the variable-value defined outside a method cannot be referenced in the method.
To solve this problem, you can use the super global variable request session post or another magic function or global, with the focus on global! There is no problem in writing the following code in a common PHP file:
$a = 1;$b = 2;function Sum(){ global $a, $b; echo $a." ",$b." "; $b = $a + $b;}Sum();echo $b;//3return $b;
But it cannot be used in a php encapsulated class.
class MyClass {private $str = "Hello, World"; function my_print() { global $str; print "str:".$str; }}
Only in this way:
class MyClass { function my_print() { global $str; print "str:".$str; }} $str = "Hello, World";$myclass = new MyClass();//$myclass->my_print();//Hello, World
I have been checking it online for a long time and found that global is invalid due to scope issues.
Some include operations may change the scope.
If you want to use global variables in the same class, try the following method:
test1();$classtest->test2();print_r($operator_stack);//Array ( [0] => 1 [1] => 2 ) exit;
The following record uses php
preg_match
Regular Expression matching is always an error
The regular expression that has been debugged by java cannot be used in this method.
Solution: Add "//" at the beginning and end of your regular expression.