PHP $this variable

前端 未结 6 1261
日久生厌
日久生厌 2020-12-29 22:28

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         


        
6条回答
  •  春和景丽
    2020-12-29 22:49

    1. With the code you've posted, you can't know what the values of $this->dbh is.
    2. $dbh is a property of the current object. $this is use to access to the members of the current object.
    3. Since this variable is defined outside of any function, is a variable that belongs to the class and not to a specific function. Because of this, $this->dbh can be used in any function inside the class.
    4. PHP doesn't require to define every variable you use.

提交回复
热议问题