How do you print an object, called * (asterisk)?
Asked Answered
D

4

5

If print_r($object) returns

stdClass Object
(
    [*] => sometext
)

How do I get the property of the asterisk, i.e $object->*?

Doby answered 12/9, 2012 at 6:36 Comment(0)
H
11

You can access the property like this

$object->{"*"}
Husain answered 12/9, 2012 at 6:39 Comment(2)
@timofey read more here Complex (curly) syntaxHusain
Thanks for the link! Great info.Doby
R
2

Does this work;

  print_r($object->{'*'});
Radcliff answered 12/9, 2012 at 6:40 Comment(0)
L
1

Just

print_r($object->{"*"});
Lowry answered 12/9, 2012 at 6:43 Comment(0)
M
1

You can also convert your object to an array :

$array = get_object_vars($object);
echo $array['*'];

But answers above are even better :

$object->{"*"}
Maddi answered 12/9, 2012 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.