PHP SET 函数中的默认参数作为静态变量
Posted
技术标签:
【中文标题】PHP SET 函数中的默认参数作为静态变量【英文标题】:PHP SET default argument in function as static variable 【发布时间】:2015-01-27 02:01:05 【问题描述】:是否可以将类函数中参数的默认值设置为静态变量 感谢您提前提供的帮助!
class UserControl
public static $CurrentUID;
public static function isUserExist($CurrentUID = UserControl::$CurrentUID)
....
【问题讨论】:
不可能,如php documentation,The default value must be a constant expression, not (for example) a variable, a class member or a function call.
中所说
啊……当然只做字符串
【参考方案1】:
在这种情况下,您可以采取一种解决方法:
public static function isUserExist($CurrentUID = false)
if(!$CurrentUID)
$CurrentUID = UserControl::$CurrentUID;
....
【讨论】:
不幸的是我的函数是在一个紧密的循环中调用的,所以条件是昂贵的以上是关于PHP SET 函数中的默认参数作为静态变量的主要内容,如果未能解决你的问题,请参考以下文章