@@ -77,12 +77,18 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | $err = null; |
| 79 | 79 | |
| 80 | - if (empty($index)) return $item; |
|
| 80 | + if (empty($index)) { |
|
| 81 | + return $item; |
|
| 82 | + } |
|
| 81 | 83 | |
| 82 | 84 | $key = array_shift($index); |
| 83 | 85 | |
| 84 | - if ((is_array($item) || $item instanceof \Traversable) && isset($item[$key])) return static::getValue($item[$key], $index, $ignore, $err); |
|
| 85 | - if (is_object($item) && isset($item->$key)) return static::getValue($item->$key, $index, $ignore, $err); |
|
| 86 | + if ((is_array($item) || $item instanceof \Traversable) && isset($item[$key])) { |
|
| 87 | + return static::getValue($item[$key], $index, $ignore, $err); |
|
| 88 | + } |
|
| 89 | + if (is_object($item) && isset($item->$key)) { |
|
| 90 | + return static::getValue($item->$key, $index, $ignore, $err); |
|
| 91 | + } |
|
| 86 | 92 | |
| 87 | 93 | if ((!is_object($item) && !is_array($item)) || !$ignore) { |
| 88 | 94 | $err = (object)['var' => isset($item) ? gettype($item) : null, 'incomplete' => count($index) + 1]; |
@@ -156,16 +162,24 @@ discard block |
||
| 156 | 162 | return; |
| 157 | 163 | } |
| 158 | 164 | |
| 159 | - if (!isset($item->$key) && $create) $item->$key = $create === 'array' ? [] : (object)[]; |
|
| 160 | - if (isset($item->$key)) return static::setValue($item->$key, $index, $value, $create, $err); |
|
| 165 | + if (!isset($item->$key) && $create) { |
|
| 166 | + $item->$key = $create === 'array' ? [] : (object)[]; |
|
| 167 | + } |
|
| 168 | + if (isset($item->$key)) { |
|
| 169 | + return static::setValue($item->$key, $index, $value, $create, $err); |
|
| 170 | + } |
|
| 161 | 171 | } elseif (is_array($item)) { |
| 162 | 172 | if (empty($index)) { |
| 163 | 173 | $item[$key] = $value; |
| 164 | 174 | return; |
| 165 | 175 | } |
| 166 | 176 | |
| 167 | - if (!isset($item[$key]) && $create) $item[$key] = $create === 'array' ? [] : (object)[]; |
|
| 168 | - if (isset($item[$key])) return static::setValue($item[$key], $index, $value, $create, $err); |
|
| 177 | + if (!isset($item[$key]) && $create) { |
|
| 178 | + $item[$key] = $create === 'array' ? [] : (object)[]; |
|
| 179 | + } |
|
| 180 | + if (isset($item[$key])) { |
|
| 181 | + return static::setValue($item[$key], $index, $value, $create, $err); |
|
| 182 | + } |
|
| 169 | 183 | } else { |
| 170 | 184 | $err = (object)['var' => gettype($item), 'incomplete' => count($index) + 1]; |
| 171 | 185 | return; |
@@ -214,13 +228,21 @@ discard block |
||
| 214 | 228 | $key = array_shift($index); |
| 215 | 229 | |
| 216 | 230 | if (empty($index)) { |
| 217 | - if (is_object($item) && isset($item->$key)) unset($item->$key); |
|
| 218 | - if (is_array($item) && isset($item[$key])) unset($item[$key]); |
|
| 231 | + if (is_object($item) && isset($item->$key)) { |
|
| 232 | + unset($item->$key); |
|
| 233 | + } |
|
| 234 | + if (is_array($item) && isset($item[$key])) { |
|
| 235 | + unset($item[$key]); |
|
| 236 | + } |
|
| 219 | 237 | return; |
| 220 | 238 | } |
| 221 | 239 | |
| 222 | - if (is_object($item) && isset($item->$key)) return static::removeValue($item->$key, $index, $err); |
|
| 223 | - if (is_array($item) && isset($item[$key])) return static::removeValue($item[$key], $index, $err); |
|
| 240 | + if (is_object($item) && isset($item->$key)) { |
|
| 241 | + return static::removeValue($item->$key, $index, $err); |
|
| 242 | + } |
|
| 243 | + if (is_array($item) && isset($item[$key])) { |
|
| 244 | + return static::removeValue($item[$key], $index, $err); |
|
| 245 | + } |
|
| 224 | 246 | } |
| 225 | 247 | |
| 226 | 248 | |