Adding failing test for Ocramius/ProxyManager#116 - public properties defaults are ignored#122
Conversation
There was a problem hiding this comment.
@Ocramius I don't understand this line, do you force initializer to be null ? It's a BC and a problem because sometimes we need to keep initializer not null no ?
There was a problem hiding this comment.
@blanchonvincent setting multiple properties is going to trigger initialization multiple times via __set(). That's why I have to set the initializer to null
Got any alternative approach?
There was a problem hiding this comment.
@Ocramius maybe use isset() to check if property if initialized ? or add a static flag in __call method ?
There was a problem hiding this comment.
@blanchonvincent the initializer is always either Closure or null - can't be false. The other way would be to have another private property that is a flag like "I'm currently initializing myself, don't recurse initialization", but it's kinda bloated.
I'll think about it before merging though, good catch on the BC break!
There was a problem hiding this comment.
@Ocramius I thought about the isset with the line below :
if (!isset(\$this->\$key)) {
\$this->\$key = \$default;
}instead of
\$this->\$key = \$default;There was a problem hiding this comment.
@blanchonvincent at this point, isset($this->$key) will trigger calls to __isset() for each property
There was a problem hiding this comment.
@Ocramius ha ha right ! sorry, it was a bad idea. The flag can be cool but it's annoying
There was a problem hiding this comment.
Something like:
if ($this->startedInitializing230874208y80) {
return;
}
$this->startedInitializing230874208y80 = true;
// do other things
$this->initializer0837082470397409->__invoke(...);
$this->startedInitializing230874208y80 = false;Think it's acceptable?
|
@blanchonvincent I included a test to fix the bc break |
There was a problem hiding this comment.
@Ocramius Why ? If initialization is set to false, public properties will set each time there is a method call no ?
There was a problem hiding this comment.
Ouch! Good point! Will fix :-)
There was a problem hiding this comment.
@Ocramius Is there no change about this line before the merge ?
There was a problem hiding this comment.
@blanchonvincent didn't find any other breakages, and added tests to verify that your use cases are covered ;)
There was a problem hiding this comment.
@Ocramius try this plz : https://gist.github.com/blanchonvincent/7699952 (there is also an other error with a problem with a reference)
There was a problem hiding this comment.
I have an example for multiple initialization, but it is indeed broken. An initializer like:
function (BaseClass $proxy, $method, $parameters, & $initializer) use ($identifier, $someRepo) {
if ($proxy->isInitialized() && ! $someRepo->checkChanged($identifier)) {
return;
}
// reset properties
};That's the kind of "advanced" usage that I can think of, but it would not really work with public properties...
There was a problem hiding this comment.
As for setting the initializer always to null, I'm +1 for that, but only in another major. Mind opening an issue with that?
There was a problem hiding this comment.
A fix for the broken behavior that I've shown in #122 (comment) may be to unset all public properties AGAIN when triggering initialization.
There was a problem hiding this comment.
@blanchonvincent I opened #126 with the failure you randomly discovered with the non-existing property :-)
…ties-defaults Adding failing test for #116 - public properties defaults are ignored
This is a hotfix for #116