开发者

PHP: How do I add a parameter to an object reference?

开发者 https://www.devze.com 2023-01-21 13:54 出处:网络
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] => 1377

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号