This is a very straightforward question that doesn’t appear to be directly addressed at php.com – at least from looking through that section.
In any case, I have a class here with a specific function:
class CheckOut extends DB_MySQL{
public $fName;
public $lName;
public $numberOut;
public $p_id;
/.../
protected function publisherCheck($lName, $fName)
{
$this->lName = $lName;
$this->fName = $fName;
//Execute test
$this->checkConnect();
$stmt = $this->dbh->prepare("SELECT p_id FROM People WHERE lastName = :param1 AND firstName = :param2");
$stmt->bindParam(':param1', $this->lName);
$stmt->bindParam(':param2', $this->fName);
$stmt->execute();
//Determine value of test
if($stmt == FALSE)
{
return FALSE;
}
else
{
$p_id = $stmt->fetch();
}
}
Just ignore the fact that there is no constructor posted with missing functions, etc. They’re in this class – just not pertinent to my question.
Will setting $p_id in the last statement affect the variable declared initially in the header of the class? Essentially, will it be global within the class?
Any help is appreciated.
Nope, it won’t. You always need
$this->to tell PHP you’re talking about the class properties, not local variables.