Indirect modification of overloaded property

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rupo
Forum Commoner
Posts: 25
Joined: Thu Jul 05, 2007 11:22 am

Indirect modification of overloaded property

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

foreach only works on arrays and objects.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

He's casting it to an array.

Where in the script does the error show up?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please update to php 5.2.2 or newer.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
Post Reply