Page 1 of 1

Indirect modification of overloaded property

Posted: Thu Jul 05, 2007 1:34 pm
by Rupo
Hi,

new here I've another question. I'm using a little Template class in php 5.21.

But php send the following error:
Indirect modification of overloaded property
the class

Code: Select all

class XTemplate
{
    private $_variables = array();


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


    public function __get($key)
    {
        if (!array_key_exists($key, $this->_variables)) {
            trigger_error("xtemplate::__get(): property <i>$key</i> does not exist", E_USER_NOTICE);
            return null;
        }
        return $this->_variables[$key];
    }

    public function display($template)
    {
        if (!is_readable($template)) {
            trigger_error("xtemplate::display(): template file <i>$template</i> is not readable", E_USER_NOTICE);
            return null;
        }
        include $template;
    }
}
By adding a simple (array) to a foreach the meassage disapear:

Code: Select all

<?php foreach ((array) $this->feeds as $item):?>
i've really no idea about the reasons

so long
Rupo

Posted: Thu Jul 05, 2007 1:53 pm
by superdezign
foreach only works on arrays and objects.

Posted: Thu Jul 05, 2007 6:07 pm
by RobertGonzalez
He's casting it to an array.

Where in the script does the error show up?

Posted: Thu Jul 05, 2007 6:24 pm
by volka
Please update to php 5.2.2 or newer.

Posted: Thu Jul 05, 2007 6:35 pm
by superdezign
Everah wrote:He's casting it to an array.

Where in the script does the error show up?
I figured the question was asking why he needed to typecast it. Beyond that, I'm clueless as to what he's talking about.