[TYPO3-dev] Why isn't the constructor called for the domain model?

Stephan Schuler Stephan.Schuler at netlogix.de
Mon Oct 13 20:47:49 CEST 2014


Hey there.

Do you retreive an existing object from the database? Talking about "showAction" points to that, but that's not necessarily the case.

When looking at the live cycle of objects, the "__construct" method is to be called when an object "comes to life". When you retrieve an existing object, then it already exists and thus the __construct is *not* called by purpose.

It's all about calling proper live cycle methods. Every object gets constructed only once, every other situation where the object is recreated PHP wise isn't exactly "creating" but only "re-creating" and thus not meant to call __construct.

If you want to e.g. want to simuate something like "crdate" as a domain prperty, you woud set $this->crdate = new \DateTime() in the __construct method.

If you want to have a certain property set whenever the object enters the PHP process (like "awake") you should either use the "initializeObject()" method or __wakeup(). But since __wakeup is used by PHP for handling the actual unserialize mechanism and is required to deal with incoming raw data I would suggest to not do __wakeup and let the unserialize stuff be handle autmatically.
This leave you initializeObject() only.

Regards,


Stephan Schuler
Web-Entwickler

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Website: media.netlogix.de



----------------------------
Woche der 79ers vom 27. bis 31. Oktober: Microsoft SCCM, Veeam Backup, Citrix XenDesktop, Sophos, Office365
5 Tage, 5 Themen – je 79 Euro. Jetzt anmelden unter http://it-training.netlogix.de/leistungen-angebote/79ers
----------------------------




netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Neuwieder Straße 10 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Internet: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt



________________________________________
Von: typo3-dev-bounces at lists.typo3.org [typo3-dev-bounces at lists.typo3.org]" im Auftrag von "Olle Haerstedt [o.haerstedt at bitmotion.de]
Gesendet: Montag, 13. Oktober 2014 16:09
An: typo3-dev at lists.typo3.org
Betreff: [TYPO3-dev]  Why isn't the constructor called for the domain model?

Hi!

Why isn't the __constructor called for the domain model when doing a simple
showAction? I need to initialize an object storage. Even if I `die` in the constructor,
it won't die. I know I'm in the right model, cause when I `die` in a setter, execution
stops as expected. Same thing when cache is emptied.

A guy on IRC mentioned that Extbase uses `unserialize` to create objects. Is this
related?

Regards
Olle
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev


More information about the TYPO3-dev mailing list