0
class Renderer
{
    private $data;

    public function __construct()
    {
        $this->data = array();
    }

    public function __get($key)
    {
        return array_key_exists($key, $this->data) ? $this->data[$key] : null;
    }

    public function __set($key, $value)
    {
        $this->data[$key] = $value;
    }
}

When I check empty($renderer->param) it returns false even if var_dump($renderer->param) returns correct value.

Is it that php checks for parameter inside class when it's stored in array or am I missing something?

0

1 Answer 1

3

You could (should?) implement an __isset() method. The manual on empty() says:

When using empty() on inaccessible object properties, the __isset() overloading method will be called, if declared.

Sign up to request clarification or add additional context in comments.

2 Comments

For your convenience, here is a snipplet for what you want: gist.github.com/pinoniq/6039523
That was the case, thank you :) I would have had bad headache figuring it out, @Pinoniq thanks for snipplet too.

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.