PHP $this variable

前端 未结 6 1259
日久生厌
日久生厌 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:46

    PHP doesn't force you to declare you class properties but will create them for you when first accessed. Whether this is good or bad, be that as it may, welcome to PHP.

    Another thing to check is that you don't have any inheritance happening. Was your $dbh property defined in a parent class? There isn't anything in the simple code you posted but I can imagine that you simplified a bit for public consumption. :-)

提交回复
热议问题