不要在全球范围内取消你需要的变量 [英] Don?t unset that variable you need globally
问题描述
不要?弄错了。这是昂贵的。
假设您已在主脚本中定义了一个变量$ var。
现在在一个函数中,您可以使用以下命令访问它:
global $ var;
但是你想在函数内部将它设置为null。
DO:$ var = null ;
不要这样做:未设置($ var);
为什么?因为第二种方式从名称空间中删除变量,
并且它不再是全局可用的。花了我10个小时....
-
发表时使用 http://www.dbforumz.com 界面,应作者的要求
单独检查文章是否符合usenet标准
主题网址: http:/ /www.dbforumz.com/PHP-Don-unse...ict237516.html
访问主题网址以联系作者(reg.req''d)。举报滥用行为: http://www.dbforumz.com/eform.php ?p = 825331
Dont? make my mistake. It is costly.
Say you have defined a variable $var in your main script.
Now in a function you access it using:
global $var;
But you want to set it to null inside the function.
DO: $var = null;
DONT DO: unset($var);
Why? Because the 2nd way removes the variable from the name space,
and it is no longer globally available. Cost me 10 hours....
--
Posted using the http://www.dbforumz.com interface, at author''s request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-Don-unse...ict237516.html
Visit Topic URL to contact author (reg. req''d). Report abuse: http://www.dbforumz.com/eform.php?p=825331
推荐答案
var在你的主脚本中。
现在在你可以使用以下功能访问它:
global
var in your main script.
Now in a function you access it using:
global
var;
但是你想把它设置为null函数。
DO:
var;
But you want to set it to null inside the function.
DO:
var = null;
不要做:取消设置(
var = null;
DONT DO: unset(
这篇关于不要在全球范围内取消你需要的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!