What does using the dollar sign after $ this-> mean in PHP?

I am a little confused by some PHP syntax that I came across. Here is an example:

$k = $this->_tbl_key;

if( $this->$k)
{
   $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls );
}
else
{
    $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key );
}

My question basically means what does it mean $this->$k? I figured this could mean a member variable that goes by the name of what is in $this->_tbl_key, but how will it work? Is it possible to add member variables to a class at runtime?

+5
source share
2 answers

He will look for what has the value "k", and consider it as the name of a variable. These two patterns are the same:

echo ($obj->myvar);

####

$k = "myvar";
echo ($obj->$k);
+19
source

I believe this is a case of variable variables .

+5
source

All Articles