up vote 0 down vote favorite

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.

link|flag
5  
Nothing in your code-sample writes to the object. it's all read and compare... – Bob Fanger Sep 29 at 21:46

1 Answer

up vote 0 down vote accepted

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;
    }
}
link|flag

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.