I get this strange error. You will say: "Why is it strange? You do not have such property." No. The problem is that there is a property.
There I get an error message.
// PHP Notice: Undefined property: stdClass::$roles in $canWrite = $this->session->isLoggedIn() ? $this->page->canWrite($this->session->user->roles) : false;
This is a class.
class User { protected $roles; function getRoles() { if (!$this->roles) {
So this method is called when I try to access a property on this line. Everything is working fine, but I do not want to increase my error log. What's happening?
UPD1
$this->user->session - User object
function getUser() { if (!$this->user) { $u = new User();
User Object ( [roleId:protected] => 1 [roles:protected] => Array ( [root] => Role Object ( [id:protected] => 1 [hrefname:protected] => root ) ) )
UPD2
All properties are accessed through magic __get()
public function __get($var) { if ($this->__isset($var)) { $method = 'get'.ucfirst($var); if (method_exists($this, $method)) { return $this->$method(); } else { return $this->$var; } } throw new Exception("Unrecognized attribute '$name'"); }
UPD3
var_dump($this->session->user)
object(User)
Explanation
In one place, I accidentally wrote $this->session->user->id = $user->id , where $this->session->user has not been created yet. So null->id really was (new stdClass())->id . Ok, thanks, PHP.
source share