如何在不执行$ foo-> value的情况下在php中打印对象的值? [关闭]

I want to be able to get the value of a php object without having to do $foo->value. Similar to how a variable works ex.

$foo = "bar";
print $foo;

The line printed is bar.

You could use print_r() or var_dump() or var_export() to get a textual representation of your object.

Each of those functions is used by passing in an expression; it could be an object, an array, or a value.

There's no such thing as a "default value" for an object, so this doesn't work. The closest you can get is with the magic __toString method, which controls as what kind of string value the object is printed in a string context.

I believe you are looking for extract()

extract($foo);
print $value1;
print $value2;
print $value3;