src/AbstractCollectionPlus.php
public function exchangeArray($dataSet)
    {
        if (is_object($dataSet))
        {
            switch(true)
            {
                case is_callable(array($dataSet, 'getArrayCopy'), false):
                    $dataSet = $dataSet->getArrayCopy();
                    break;
                case is_callable(array($dataSet, 'toArray'), false):
                    $dataSet = $dataSet->toArray();
                    break;
                case is_callable(array($dataSet, '__toArray'), false):
                    $dataSet = $dataSet->__toArray();
                    break;
                case ($dataSet instanceof \stdClass):
                    $dataSet = (array)$dataSet;
                    break;

                default:
                    throw new \InvalidArgumentException(vsprintf(
                        '%s - Unable to exchange data with object of class "%s".',
                        array(get_class($this), get_class($dataSet)))
                    );
            }
        }

        if (is_array($dataSet))
        {
            $prevStorage = $this->_storage;
            $this->_storage = $dataSet;
            $this->_modified = true;
            return $prevStorage;
        }

        throw new \InvalidArgumentException(vsprintf(
            '%s::exchangeArray expects parameter 1 to be array or object, "%s" seen.',
            array(get_class($this), gettype($dataSet))
        ));
    }
public function exchangeArray($dataSet)
    {
        if (is_object($dataSet))
        {
            switch(true)
            {
                case is_callable(array($dataSet, 'getArrayCopy'), false):
                    $dataSet = $dataSet->getArrayCopy();
                    break;
                case is_callable(array($dataSet, 'toArray'), false):
                    $dataSet = $dataSet->toArray();
                    break;
                case is_callable(array($dataSet, '__toArray'), false):
                    $dataSet = $dataSet->__toArray();
                    break;
                case ($dataSet instanceof \stdClass):
                    $dataSet = (array)$dataSet;
                    break;

                default:
                    throw new \InvalidArgumentException(vsprintf(
                        '%s - Unable to exchange data with object of class "%s".',
                        array(get_class($this), get_class($dataSet)))
                    );
            }
        }

        if (is_array($dataSet))
        {
            $prevStorage = $this->_storage;
            $this->_storage = $dataSet;
            $this->_modified = true;
            return $prevStorage;
        }

        throw new \InvalidArgumentException(vsprintf(
            '%s::exchangeArray expects parameter 1 to be array or object, "%s" seen.',
            array(get_class($this), gettype($dataSet))
        ));
    }
public function exchangeArray ( $ dataSet ) { if ( is_object ( $ dataSet ) ) { switch ( true ) { case is_callable ( array ( $ dataSet , 'getArrayCopy' ) , false ) : $ dataSet = $ dataSet -> getArrayCopy ( ) ; break ; case is_callable ( array ( $ dataSet , 'toArray' ) , false ) : $ dataSet = $ dataSet -> toArray ( ) ; break ; case is_callable ( array ( $ dataSet , '__toArray' ) , false ) : $ dataSet = $ dataSet -> __toArray ( ) ; break ; case ( $ dataSet instanceof \ stdClass ) : $ dataSet = ( array ) $ dataSet ; break ; default : throw new \ InvalidArgumentException ( vsprintf ( '%s - Unable to exchange data with object of class "%s".' , array ( get_class ( $ this ) , get_class ( $ dataSet ) ) ) ) ; } } if ( is_array ( $ dataSet ) ) { $ prevStorage = $ this -> _storage ; $ this -> _storage = $ dataSet ; $ this -> _modified = true ; return $ prevStorage ; } throw new \ InvalidArgumentException ( vsprintf ( '%s::exchangeArray expects parameter 1 to be array or object, "%s" seen.' , array ( get_class ( $ this ) , gettype ( $ dataSet ) ) ) ) ; }
This method was inspired by Zend Framework 2.2.x PhpReferenceCompatibility class

@link https://github.com/zendframework/zf2/blob/release-2.2.6/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php#L179

@param $dataSet
@return array
@throws \InvalidArgumentException
This method was inspired by Zend Framework 2 . 2 . x PhpReferenceCompatibility class