views:

42

answers:

1

Hi

I have code like this:

foreach($attributes as $attrib => $options){
     if($bb->$attrib != $default->$attrib){
        $delete = false;
    }
}

$bb is a stdClass, im reading and writing these attributes to it in this way, because I have them stored in an array. Now this works in PHP 5.3 which I have confirmed, I'm pretty sure it works on 5.2 too, but on 5.1 there seems to be an issue where you can not write to the object in this way, no errors or anything, it just won't write...

Does anyone know what is the problem? Since what version does it work? I looked in the PHP documentation but I can't find anything about this.

A: 

I believe he's referring to using variable variables, for PHP <= 5.1 try using {} around the variable variable. iirc in PHP 5.2+ is when some things got changed to allow it without those. Also it's possible that before 5.2.x this wasn't allowed, and reason it isn't given errors perhaps error handling isn't setup all the way, or limited to just E_ERROR.

foreach($attributes as $attrib => $options){
     if($bb->{$attrib} != $default->{$attrib}){
        $delete = false;
    }
}
Viper_Sb