您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 甘孜分类信息网,免费分类信息发布

php基础-范例:global和static的使用和区别

2025/9/27 7:56:55发布28次查看
php基础-实例:global和static的使用和区别
? function testgloabl(){
? ? global $testgloabl;
? ? $testgloabl = 2;
? ? $testgloabl ++;
}
testgloabl();
echo $testgloabl.||.$globals['testgloabl'];
function teststatic(){
? ? static $teststatic = 2;
? ? $teststatic ++;
}
? teststatic();
? echo $teststatic;//使用static关键字的变量,在函数外部访问将会提示 $teststatic未定义;
?
说明:
1.使用global定义的关键字,当这个关键字所在函数被调用后,它将在当前脚本的任何位置可以被访问到
2.使用static定位的关键字,当这个关键字所在函数内被访问,该函数外其他地方无法访问到。
共同点:global? static 都可以使定位的变量指向同一块内存区域。
甘孜分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product