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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.