src/ContainerUnsetCapableTrait.php
protected function _containerUnset(&$container, $key)
    {
        $origKey = $key;
        $key     = $this->_normalizeKey($key);

        if (is_array($container)) {
            if (!isset($container[$key])) {
                throw $this->_createNotFoundException($this->__('Key "%1$s" not found', [$key]), null, null, null, $key);
            }

            unset($container[$key]);

            return;
        }

        if ($container instanceof stdClass) {
            if (!isset($container->{$key})) {
                throw $this->_createNotFoundException($this->__('Key "%1$s" not found', [$key]), null, null, null, $key);
            }

            unset($container->{$key});

            return;
        }

        if ($container instanceof ArrayAccess) {
            try {
                $hasKey = $container->offsetExists($key);
            } catch (RootException $e) {
                throw $this->_createContainerException($this->__('Could not check key "%1$s" on container', [$key]), null, $e, null);
            }

            if (!$hasKey) {
                throw $this->_createNotFoundException($this->__('Key "%1$s" not found', [$key]), null, null, null, $key);
            }

            try {
                $container->offsetUnset($key);

                return;
            } catch (RootException $e) {
                throw $this->_createContainerException($this->__('Could not unset key "%1$s" on container', [$key]), null, $e, null);
            }
        }

        throw $this->_createInvalidArgumentException($this->__('Invalid container'), null, null, $container);
    }
protected function _containerUnset(&$container, $key)
    {
        $origKey = $key;
        $key     = $this->_normalizeKey($key);

        if (is_array($container)) {
            if (!isset($container[$key])) {
                throw $this->_createNotFoundException($this->__('Key "%1$s" not found', [$key]), null, null, null, $key);
            }

            unset($container[$key]);

            return;
        }

        if ($container instanceof stdClass) {
            if (!isset($container->{$key})) {
                throw $this->_createNotFoundException($this->__('Key "%1$s" not found', [$key]), null, null, null, $key);
            }

            unset($container->{$key});

            return;
        }

        if ($container instanceof ArrayAccess) {
            try {
                $hasKey = $container->offsetExists($key);
            } catch (RootException $e) {
                throw $this->_createContainerException($this->__('Could not check key "%1$s" on container', [$key]), null, $e, null);
            }

            if (!$hasKey) {
                throw $this->_createNotFoundException($this->__('Key "%1$s" not found', [$key]), null, null, null, $key);
            }

            try {
                $container->offsetUnset($key);

                return;
            } catch (RootException $e) {
                throw $this->_createContainerException($this->__('Could not unset key "%1$s" on container', [$key]), null, $e, null);
            }
        }

        throw $this->_createInvalidArgumentException($this->__('Invalid container'), null, null, $container);
    }
protected function _containerUnset ( & $ container , $ key ) { $ origKey = $ key ; $ key = $ this -> _normalizeKey ( $ key ) ; if ( is_array ( $ container ) ) { if ( ! isset ( $ container [ $ key ] ) ) { throw $ this -> _createNotFoundException ( $ this -> __ ( 'Key "%1$s" not found' , [ $ key ] ) , null , null , null , $ key ) ; } unset ( $ container [ $ key ] ) ; return ; } if ( $ container instanceof stdClass ) { if ( ! isset ( $ container -> { $ key } ) ) { throw $ this -> _createNotFoundException ( $ this -> __ ( 'Key "%1$s" not found' , [ $ key ] ) , null , null , null , $ key ) ; } unset ( $ container -> { $ key } ) ; return ; } if ( $ container instanceof ArrayAccess ) { try { $ hasKey = $ container -> offsetExists ( $ key ) ; } catch ( RootException $ e ) { throw $ this -> _createContainerException ( $ this -> __ ( 'Could not check key "%1$s" on container' , [ $ key ] ) , null , $ e , null ) ; } if ( ! $ hasKey ) { throw $ this -> _createNotFoundException ( $ this -> __ ( 'Key "%1$s" not found' , [ $ key ] ) , null , null , null , $ key ) ; } try { $ container -> offsetUnset ( $ key ) ; return ; } catch ( RootException $ e ) { throw $ this -> _createContainerException ( $ this -> __ ( 'Could not unset key "%1$s" on container' , [ $ key ] ) , null , $ e , null ) ; } } throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid container' ) , null , null , $ container ) ; }
Unsets a value with the specified key on the given container.

@since [*next-version*]

@param array|ArrayAccess|stdClass       $container The writable container to unset the value on.
@param string|int|float|bool|Stringable $key       The key to unset the value for.

@throws InvalidArgumentException    If the container is invalid.
@throws OutOfRangeException         If the key is invalid.
@throws NotFoundExceptionInterface  If the key is not found.
@throws ContainerExceptionInterface If problem accessing the container.
Unsets a value with the specified key on the given container .