1. There is no global static variable in PHP. When I used to do .Net development, I could use the following method to cache some data: view plaincopy to clipboardprint? public class Test{ PHP is an interpreted language. Although it has the static modifier, its meaning is completely different from that in .Net. 2. Understand variable scope. Variables declared outside the method cannot be accessed within the method body. view plaincopy to clipboardprint? $url = "www.webjx.com"; _DisplayUrl method will not display any results because the variable $url is inaccessible in the method body _DisplayUrl. Just add global before $url, such as the DisplayUrl method. Global variables defined in the method body can be accessed outside the method: view plaincopy to clipboardprint?
public class Test {
private static int Count = 0; //This variable is valid throughout the application.
}
private static int Count = 0; //This variable is valid throughout the application.
}
Even if a variable in the class is declared as static, this variable is only valid in the current page-level application domain.
For example:
$url = "www.webjx.com";
function _DisplayUrl() {
echo $url;
}
function DisplayUrl() {
global $url;
echo $url;
}
_DisplayUrl();
DisplayUrl();
?>
function _DisplayUrl() {
echo $url;
}
function DisplayUrl(){
global $url;
echo $url;
}
_DisplayUrl();
DisplayUrl();
?>
function _DisplayUrl() {
global $myName;
$myName=yibin;
}
_DisplayUrl( );
echo $myName; //output yibin
?>