How do I remove a value from an object converted to an array in php?

I want to get the value converted to an array and then to an object.

$input = (object)(array) 123;
var_dump($input);

It is output:

object(stdClass)#1 (1) {
  [0]=>
  int(123)
}

How to get value 123 from $input?

+3
source share
2 answers

https://bugs.php.net/bug.php?id=45959

Unfortunately, this is a known issue that you cannot do anything about.

If you are stuck with an object of this type from an external source, the best bet will be passed to it in an array to get the value:

$input = (object)(array) 123;
$array = (array) $input;
echo $array[0];
+5
source

Try this code:

<pre><?php
$input = (object)(array) 123;

$reflection = new ReflectionObject($input);
var_dump($reflection->hasProperty('0'));
?></pre>

This will show you that although you can still see the value in var_dump($input), it is not considered a property. And if you ask getProperties(), you will not get any conclusion.

.. , , , ? , , .

+1

All Articles