tags:

views:

40

answers:

1

Hi there,

If i have an stdObject say, $a.

Sure there's no problem to assign a new property, $a,

$a->new_property = $xyz;

But then I want to remove it, so unset is of no help here.

So,

$a->new_property = null;

Is kind of it. But is there a more 'elegant' way?

Thanks in advance.

+9  A: 
unset($a->new_property);

this works for array elements, variables, and object attributes

** EDIT **

I don't know how you were using unset(), but this is how it works for me :

$a = new stdClass();

$a->new_property = 'foo';
var_export($a);  // -> stdClass::__set_state(array('new_property' => 'foo'))

unset($a->new_property);
var_export($a);  // -> stdClass::__set_state(array())
Yanick Rochon
Thanks, my silliness :) It works all ok! :)
valk