Bug #43659

Proxy class building calls __construct and initializeObject before DI objects are present

Added by Stephan Schuler over 8 years ago. Updated almost 7 years ago.

Status:
Resolved
Priority:
Must have
Assignee:
Category:
Object
Start date:
2012-12-06
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

Hey there.

Given the following situation:

class ObjectA;
class ObjectB extends ObjectA;
class ObjectC extends ObjectB;

The code of pre 1.1 did this:


new ObjectC ();

ObjectC_Proxy::__construct(); // triggered by my code
ObjectC_Original::__construct(); // triggered autoamtically by ObjectA_Proxy::__construct(), directly addressed as parent::__construct()

ObjectB_Proxy::__construct(); // triggered autoamtically by ObjectC_Proxy::__construct(), directly addressed as parent::__construct()
ObjectB_Original::__construct(); // triggered autoamtically by ObjectC_Proxy::__construct(), directly addressed as parent::__construct()

ObjectA_Proxy::__construct(); // triggered autoamtically by ObjectB_Proxy::__construct(), directly addressed as parent::__construct()
ObjectA_Original::__construct(); // triggered autoamtically by ObjectB_Proxy::__construct(), directly addressed as parent::__construct()

ObjectC_Proxy::DI(); // Should be ObjectA_Proxy, but it's "$this->", so the most outer method is used. But doesn't matter because it works.
ObjectC_Original::initializeObject(); // Should be ObjectA_Original, but it's "$this->", so the most outer method is used. But doesn't matter, it works.

ObjectC_Proxy::DI(); // Should be ObjectB_Proxy, but it's "$this->", so the most outer method is used. But doesn't matter because it has nothing to do.
ObjectC_Original::initializeObject(); // Should be ObjectB_Original, but it's "$this->" as well.

ObjectC_Proxy::DI(); // This should really be ObjectC_Proxy. But doesn't mater, it has been called three times before
ObjectC_Original::initializeObject(); // This should really be ObjectC_Original. But doesn't mater, it has been called three times before

The current code acts like this:


new ObjectC ();

ObjectC_Proxy::__construct(); // triggered by my code
ObjectC_Original::__construct(); // triggered autoamtically by ObjectA_Proxy::__construct(), directly addressed as parent::__construct()

ObjectB_Proxy::__construct(); // triggered autoamtically by ObjectC_Proxy::__construct(), directly addressed as parent::__construct()
ObjectB_Original::__construct(); // triggered autoamtically by ObjectC_Proxy::__construct(), directly addressed as parent::__construct()

ObjectA_Proxy::__construct(); // triggered autoamtically by ObjectB_Proxy::__construct(), directly addressed as parent::__construct()
ObjectA_Original::__construct(); // triggered autoamtically by ObjectB_Proxy::__construct(), directly addressed as parent::__construct()

ObjectC_Original::initializeObject(); // Should be ObjectA_Original, but it's "$this->", so the most outer method is used. This is way to early, no DI done until now.

ObjectC_Original::initializeObject(); // Should be ObjectB_Original, but it's "$this->" as well. To early, too.

ObjectC_Proxy::DI(); // Now we get the correct DI, but a little to late.
ObjectC_Original::initializeObject(); // This is the first call of ObjectC_Original::initializeObject() that really acts as expected since the other two calls had no DI properties available.

In my oppinion, the DI sould be available in __construct. So I would move the DI stuff right before __construct and introduce a boolean helper flag to avoid multiple calls of DI. In general, I would call Flow_Proxy_injectProperties seeral times but make the injected method aware of multiple calls. This should clean up the genreated __construct a little.

Please see my DependencyHierarchy*.tar.gz demo files attached. Those show tue current and past situation and demonstrate the error.


Files

DependencyHierarchy-1.1.tar.gz (1.69 KB) DependencyHierarchy-1.1.tar.gz Stephan Schuler, 2012-12-06 13:21
DependencyHierarchy-1-2.tar.gz (1.78 KB) DependencyHierarchy-1-2.tar.gz Stephan Schuler, 2012-12-06 13:21

Related issues

Has duplicate TYPO3.Flow - Bug #47975: initializeObject in a Entity is called at a time where no properties are loadedResolvedRobert Lemke2013-05-06

Actions
#2

Updated by Robert Lemke over 7 years ago

  • Status changed from New to Accepted
  • Assignee set to Robert Lemke
  • Target version set to 2.x
#3

Updated by Gerrit Code Review over 7 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24550

#4

Updated by Gerrit Code Review over 7 years ago

Patch set 1 for branch 2.0 of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/27208

#5

Updated by Robert Lemke almost 7 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF