getObjectFieldValue() public static method

Accesses the field of a given object. This field has to be public directly or indirectly (through an accessor get*, is*, or a magic method, __get, __call).
public static getObjectFieldValue ( object $object, string $field ) : mixed
$object object
$field string
return mixed
 /**
  * @param object $object
  * @param string $field
  *
  * @return mixed
  */
 public static function getObjectFieldValue($object, $field)
 {
     $propertyAccess = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->enableExceptionOnInvalidIndex()->getPropertyAccessor();
     try {
         return $propertyAccess->getValue($object, $field);
     } catch (NoSuchPropertyException $e) {
         return parent::getObjectFieldValue($object, $field);
     }
 }
 public function testGetObjectFieldValueMagicCallMethod()
 {
     $object = new TestObject(1, 2, true, 3);
     $this->assertEquals(3, $this->visitor->getObjectFieldValue($object, 'qux'));
 }