0

I get a value from a database, and if I dump it, I have:

myvar=stdClass::__set_state(array(
   'id' => '320646',
   'nameNormalized' => '27817759',
   'name' => 'Thename'
))

How could it be possible to create this same variable by hand? When I do this:

$myvar= new \stdClass(array(
   'id' => '320646',
   'nameNormalized' => '27817759',
   'name' => 'Thename',
));
var_export($myvar);

I get:

stdClass::__set_state(array(
))

Then how to do?

2
  • 1
    stdClass doesn't take a param. And there isn't an "array in it". You confuse the constructor with the __set_state method. What you're looking for is a typecast: (object) array(...). Commented Feb 4, 2015 at 6:29
  • @mario did beat me to it :D codepad.viper-7.com/6MOGYS Commented Feb 4, 2015 at 6:31

1 Answer 1

2

Here's the solution:

$myvar= (object)(array(
   'id' => '320646',
   'nameNormalized' => '27817759',
   'name' => 'Thename',
));
Sign up to request clarification or add additional context in comments.

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.