1

Seems like a simple enough question, so my apologies for asking. As a precursor I'm not necessarily 'new', but rather not so well-versed in PHP.

I have a class, declared as follows:

class User
{
    public $id = "";

    public function User()
    {
        $this->$id = isset($_COOKIE['userid']) ? $_COOKIE['userid'] : 0;
    }
}

Which seems simple enough, however - upon construction, I get the following set of errors:

Notice: Undefined variable: id in D:\xampp\htdocs\sitecore\include\classes.php on line 13

Fatal error: Cannot access empty property in D:\xampp\htdocs\sitecore\include\classes.php on line 13

Sorry for asking something so simple. The line in question starts with "$this->$id".

1 Answer 1

9

Remove the $ symbol at the 'id' place:

$this->id = isset($_COOKIE['userid']) ? $_COOKIE['userid'] : 0;
Sign up to request clarification or add additional context in comments.

2 Comments

Much appreciated. Hate being a rookie.
No worry, we all need help sometimes :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.