/** * @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')); }