ZF2-239: "__clone method called on non-object" error when setting selectResultPrototype in setup() function of class extending \Zend\Db\TableGateway\AbstractTableGateway


Creating a RowGateway object as a dependency of ResultSet object to set selectResultPrototype property during the construction of a TableGateway object causes the following error:

"Fatal error: __clone method called on non-object in /var/www/pyratepunx/vendor/ZendFramework/library/Zend/Db/TableGateway/TableGateway.php on line 382"

The problem is the RowGateway constructor tries to clone the TableGateway object which tries to clone its selectResultPrototype property which is what we are trying to set and it creates a bit of a chicken and the egg situation.

The following code reproduces the error:

<?php class MyRowGateway extends \Zend\Db\RowGateway\RowGateway { } class MyTableGateway extends \Zend\Db\TableGateway\AbstractTableGateway { public function setup() { $this->selectResultPrototype = new \Zend\Db\ResultSet\ResultSet(new MyRowGateway($this, 'id')); } } $myTable = new MyTableGateway(); ?>


It's the same. And I guess that patch resolve and this.

Fixed in beta4