PHP: How do I add a parameter to an object reference?
I have an object called $object formed as follows:
stdClass Object ( [PLAYER_ID] => 141 [STATUS_ID] => 16 [LOGIN_NAME] => mikemo21 [EMAIL] => mmogilefsky@yahoo.com [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]开发者_开发百科 => mmogilefsky@yahoo.com [PT_BALANCE] => 13775 [NEW_FIELD] => VALUE)
What would be the proper syntax to accomplish something like this?
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.
精彩评论