protected static function setValue(&$item, $index, $value, $create = false, &$err = null)
    {
        $err = null;

        $key = array_shift($index);
        
        if (is_array($item) || $item instanceof \Traversable) {
            if (empty($index)) {
                $item[$key] = $value;
                return;
            }
            
            if (!isset($item[$key]) && $create) {
                $item[$key] = $create === 'array' ? [] : (object)[];
            }
            
            if (isset($item[$key])) {
                return static::setValue($item[$key], $index, $value, $create, $err);
            }
        } elseif (is_object($item)) {
            if (empty($index)) {
                $item->$key = $value;
                return;
            }
            
            if (!isset($item->$key) && $create) {
                $item->$key = $create === 'array' ? [] : (object)[];
            }
            
            if (isset($item->$key)) {
                return static::setValue($item->$key, $index, $value, $create, $err);
            }
        } else {
            $err = (object)['var' => gettype($item), 'incomplete' => count($index) + 1];
            return;
        }
        
        $err = (object)['var' => null, 'incomplete' => count($index)];
    }
protected static function setValue(&$item, $index, $value, $create = false, &$err = null)
    {
        $err = null;

        $key = array_shift($index);
        
        if (is_array($item) || $item instanceof \Traversable) {
            if (empty($index)) {
                $item[$key] = $value;
                return;
            }
            
            if (!isset($item[$key]) && $create) {
                $item[$key] = $create === 'array' ? [] : (object)[];
            }
            
            if (isset($item[$key])) {
                return static::setValue($item[$key], $index, $value, $create, $err);
            }
        } elseif (is_object($item)) {
            if (empty($index)) {
                $item->$key = $value;
                return;
            }
            
            if (!isset($item->$key) && $create) {
                $item->$key = $create === 'array' ? [] : (object)[];
            }
            
            if (isset($item->$key)) {
                return static::setValue($item->$key, $index, $value, $create, $err);
            }
        } else {
            $err = (object)['var' => gettype($item), 'incomplete' => count($index) + 1];
            return;
        }
        
        $err = (object)['var' => null, 'incomplete' => count($index)];
    }
protected static function setValue ( & $ item , $ index , $ value , $ create = false , & $ err = null ) { $ err = null ; $ key = array_shift ( $ index ) ; if ( is_array ( $ item ) || $ item instanceof \ Traversable ) { if ( empty ( $ index ) ) { $ item [ $ key ] = $ value ; return ; } if ( ! isset ( $ item [ $ key ] ) && $ create ) { $ item [ $ key ] = $ create === 'array' ? [ ] : ( object ) [ ] ; } if ( isset ( $ item [ $ key ] ) ) { return static :: setValue ( $ item [ $ key ] , $ index , $ value , $ create , $ err ) ; } } elseif ( is_object ( $ item ) ) { if ( empty ( $ index ) ) { $ item -> $ key = $ value ; return ; } if ( ! isset ( $ item -> $ key ) && $ create ) { $ item -> $ key = $ create === 'array' ? [ ] : ( object ) [ ] ; } if ( isset ( $ item -> $ key ) ) { return static :: setValue ( $ item -> $ key , $ index , $ value , $ create , $ err ) ; } } else { $ err = ( object ) [ 'var' => gettype ( $ item ) , 'incomplete' => count ( $ index ) + 1 ] ; return ; } $ err = ( object ) [ 'var' => null , 'incomplete' => count ( $ index ) ] ; }
Navigate through the item and set the value

@param array        $item
@param array        $index   The index sequence we are navigating to
@param mixed        $value
@param string|false $create  Create structure if required: 'object', 'array' or false
@param object       $err     Error object [OUTPUT]
Navigate through the item and set the value