我有下一个代码。为什么字段 userId 在 InheritUser 中不可见?
class User{
private $userId;
function User($userId){
$this->userId = $userId;
}
function getId(){
return $this->userId;
}
}
class InhreritUser extends User{
function someFunc(){
echo $this->userId; // nothing
}
}
someFunc 什么也不返回:
$inheritUser = new InheritUser(1);
$inheritUser->someFunc();