Ouzo\Utilities\Objects::getValue PHP Метод

getValue() публичный статический Метод

public static getValue ( mixed $object, string $field, null | mixed $default = null, boolean $accessPrivate = false ) : mixed | null
$object mixed
$field string
$default null | mixed
$accessPrivate boolean
Результат mixed | null
    public static function getValue($object, $field, $default = null, $accessPrivate = false)
    {
        if (is_array($object)) {
            return Arrays::getValue($object, $field, $default);
        }
        if (isset($object->{$field})) {
            return $object->{$field};
        }
        if ($accessPrivate) {
            $class = new ReflectionObject($object);
            if ($class->hasProperty($field)) {
                $property = $class->getProperty($field);
                $property->setAccessible(true);
                return $property->getValue($object);
            }
        }
        return $default;
    }

Usage Example

Пример #1
0
 public function __get($field)
 {
     $this->_operations[] = function ($input) use($field) {
         return Objects::getValue($input, $field);
     };
     return $this;
 }
All Usage Examples Of Ouzo\Utilities\Objects::getValue