<?php
class myClass {
private $private_var;
public $public_var = 'Foobar';
public function setPrivate($value)
{
$this->private_var = $value;
}
public function __debugInfo()
{
return json_decode(json_encode($this), true);
}
}
$class = new myClass();
$class->setPrivate("Baz");
print_r($class);
myClass Object
(
[public_var] => Foobar
)
參考
https://stackoverflow.com/a/48672229
https://3v4l.org/seDI6