Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8637333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:27:21+00:00 2026-06-12T10:27:21+00:00

I’m getting this strange error. You’ll say: Why strange? You just don’t have such

  • 0

I’m getting this strange error. You’ll say: “Why strange? You just don’t have such property”. No. Problem is there are property.

There I’m getting an error.

// PHP Notice:  Undefined property: stdClass::$roles in
$canWrite = $this->session->isLoggedIn() ? $this->page->canWrite($this->session->user->roles) : false;

This is the class.

class User {
    protected $roles;

    function getRoles() {
        if (!$this->roles)
        {
            // Get them!
        }

        return $this->roles;
    }
}

So this method is called when I’m trying to access property in this line. Everything works fine but I don’t want to increase my error log. What’s happening?

UPD1

$this->user->session is an User object

function getUser() {
    if (!$this->user) {
        $u = new User();
                    // Logic
        $this->user = $u;
    }
    return $this->user;
}
User Object
(
    [roleId:protected] => 1
    [roles:protected] => Array
        (
            [root] => Role Object
                (
                    [id:protected] => 1
                    [hrefname:protected] => root
                )

        )
)

UPD2

All properties are accessed via 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)#370 (30) {
  ["roles":protected]=>
  array(1) {
    ["root"]=>
    object(Role)#372 (2) {
      ["id":protected]=>
      string(1) "1"
      ["hrefname":protected]=>
      string(4) "root"
    }
  }
}

Explanation

In one place I accidentally wrote $this->session->user->id = $user->id in place where $this->session->user is not created yet. So null->id actually was (new stdClass())->id. Well, thank you, PHP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:27:22+00:00Added an answer on June 12, 2026 at 10:27 am

    Since it says the undefined property is in stdClass, this means that the object in question is not actually the User class that you think it is.

    This would generally imply that something went wrong with the creation of the object. So therefore the actual bug in your code that is leading to this error is earlier in the program than the line of code you’ve given us.

    Look for where the object is being created. That’s where the problem is likely to be.

    I can’t be of much more help than that without seeing the rest of the code, but hope that helps.

    [EDIT]

    The object that is throwing the error is $this->session->user (this is the one you’re trying to access the ->roles property for).

    As much as you want to say it’s definitely a User object, the fact is that PHP says otherwise. Do a var_dump($this->session->user) immediately before the error and you should be able to see what I’m saying.

    As for how come it isn’t what you expect, I still can’t give any better answer. Using a debugger like xDebug to trace through the program one line at a time might help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.