class MyClass { private $myProp = "Hello PHPUnit!"; } $obj = new MyClass(); $value = PHPUnit_Framework_Assert::readAttribute($obj, 'myProp'); // $value now holds the value of $myProp, which is "Hello PHPUnit!"
class Person { protected $name; protected $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } } $obj = new Person('John', 30); $name = PHPUnit_Framework_Assert::readAttribute($obj, 'name'); // $name now holds the value of $name, which is "John"In both examples, we are using the "readAttribute" method provided by the PHPUnit_Framework_Assert class to access the value of a private or protected property of an object. In terms of package library, PHPUnit is an open-source testing framework for PHP which is widely used for unit testing in PHP applications. It comes with a comprehensive set of assertion methods and other utilities which make it easier to write and run tests for PHP code.