PHP $此变量 [英] PHP $this variable
本文介绍了PHP $此变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读一些我不理解的PHP代码:
I am reading some PHP code that I could not understand:
class foo {
function select($p1, $dbh=null) {
if ( is_null($dbh) )
$dbh = $this->dbh ;
return;
}
function get() {
return $this->dbh;
}
}
我从类中找不到$this->dbh ($dbh)
声明.我的问题是:
I can't find $this->dbh ($dbh)
declaration from the class. My questions are:
-
$this->dbh
的值是什么?
它是函数select()
的局部变量吗?
Is it a local variable for function select()
?
$this
是否属于class foo
的数据成员?为什么在此类中没有$dbh
的声明?
Does $this
belong class foo
's data member? Why is there no declaration for $dbh
in this class?
推荐答案
PHP对要求类属性声明并不严格.
PHP is not strict about requiring class property declarations.
- 根据赋值,该属性将以静默方式创建.
- 从读取不存在的属性会生成一个通知,如果启用了
E_STRICT
. - 任何未定义属性的默认值为
NULL
- Upon assignation, the property is silently created.
- Reading from a non-existent property generates a Notice if
E_STRICT
is enabled. - The default value for any undefined property is
NULL
这篇关于PHP $此变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文