tags:

views:

14

answers:

1

I have an object called $object formed as follows:

stdClass Object ( [PLAYER_ID] => 141 [STATUS_ID] => 16 [LOGIN_NAME] => mikemo21 [EMAIL] => [email protected] [PT_BALANCE] => 13775 )

I'd like to add a parameter to this, perhaps so it appears as follows:

stdClass Object ( [PLAYER_ID] => 141 [STATUS_ID] => 16 [LOGIN_NAME] => mikemo21 [EMAIL] => [email protected] [PT_BALANCE] => 13775 [NEW_FIELD] => VALUE)

What would be the proper syntax to accomplish something like this?

+4  A: 

Object properties in PHP do not need to be declared before they are assigned, so you can just assign a new property like you would an existing one:

$object->new_field = $value;

See this in action at http://www.ideone.com/a8Q3t.

Daniel Vandersluis