[TYPO3-mvc] [Extbase] Object doesn't get initialized.

Stephan Schreiter sphn82 at googlemail.com
Tue Oct 12 07:48:28 CEST 2010


Hi

I have the following situation:

main_domain_model -(m:n)-> user -(1:n)-> item

In my user model I initialize the items:

class Tx_MyExt_Domain_Model_User extends 
Tx_Extbase_Domain_Model_FrontendUser {

/**
 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_Item> 
The items of a user
 **/
protected $items;

/**
 * Constructor
 **/
public function __construct() {
	$this->items = new Tx_Extbase_Persistence_ObjectStorage;
}

...

/**
 * Returns the items of the user
 *
 * @return 
Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_Item> The 
items of the user
 **/
public function getItems() {
	return clone $this->items;
}

...

}

My user model passes the unit test:

/**
 * Testcase for the User class
 **/
class Tx_MyExt_Domain_Model_UserTest extends Tx_Extbase_BaseTestCase {

/**
 * @test
 */
public function theItemsAreInitializedAsEmptyObjectStorage() {
    $user = new Tx_MyExt_Domain_Model_User;
	$this->assertEquals('Tx_Extbase_Persistence_ObjectStorage', 
get_class($user->getItems()));
	$this->assertEquals(0, count($user->getItems()->toArray()));
}

...

}

However I get the error "Fatal error: __clone method called on non-object 
in ..." when for example the $user->getItems Method gets called during 
operation.

The 'items' attribute is somehow not initialized and it is set to 'NULL'.

I have no clue about how to trace this error down. I would highly 
appreciate if somebody could help me out with a hint on where the problem 
could actually be. Is there a general mistake I might have made here?

Best thanks,

Stephan


More information about the TYPO3-project-typo3v4mvc mailing list