I’m having trouble accessing a parent’s variable like the following:
class Priveleges
{
protected $user_id;
public __construct($user_id)
{
$this->user_id = $user_id;
}
}
And now my subclass:
class userInfo extends Priveleges
{
public function __construct($user_id)
{
parent::__construct($user_id);
}
public function showID()
{
return $this->user_id;
}
}
$a = new userInfo(63);
echo $a->showID();
The ouput I would expect would be 63 wouldn’t it? However, it doesn’t output anything…
If you instead get “unexpected
__construct“, that would be because you’re missing afunctionhere:After fixing that, the output is indeed 63.