Skip to content

Adding failing test for Ocramius/ProxyManager#116 - public properties defaults are ignored#122

Merged
Ocramius merged 16 commits into
masterfrom
hotfix/issue-#116-public-properties-defaults
Nov 29, 2013
Merged

Adding failing test for Ocramius/ProxyManager#116 - public properties defaults are ignored#122
Ocramius merged 16 commits into
masterfrom
hotfix/issue-#116-public-properties-defaults

Conversation

@Ocramius

Copy link
Copy Markdown
Owner

This is a hotfix for #116

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius maybe use isset() to check if property if initialized ? or add a static flag in __call method ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius I thought about the isset with the line below :

if (!isset(\$this->\$key)) {
    \$this->\$key = \$default;
}

instead of

\$this->\$key = \$default;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blanchonvincent at this point, isset($this->$key) will trigger calls to __isset() for each property

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius ha ha right ! sorry, it was a bad idea. The flag can be cool but it's annoying

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like:

if ($this->startedInitializing230874208y80) {
    return;
}

$this->startedInitializing230874208y80 = true;

// do other things

$this->initializer0837082470397409->__invoke(...);
$this->startedInitializing230874208y80 = false;

Think it's acceptable?

@Ocramius

Copy link
Copy Markdown
Owner Author

@blanchonvincent I included a test to fix the bc break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius Why ? If initialization is set to false, public properties will set each time there is a method call no ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch! Good point! Will fix :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius Is there no change about this line before the merge ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blanchonvincent didn't find any other breakages, and added tests to verify that your use cases are covered ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius try this plz : https://gist.github.com/blanchonvincent/7699952 (there is also an other error with a problem with a reference)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for setting the initializer always to null, I'm +1 for that, but only in another major. Mind opening an issue with that?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fix for the broken behavior that I've shown in #122 (comment) may be to unset all public properties AGAIN when triggering initialization.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blanchonvincent I opened #126 with the failure you randomly discovered with the non-existing property :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.04%) when pulling b85dc27 on hotfix/issue-#116-public-properties-defaults into 44d82e7 on master.

Ocramius added a commit that referenced this pull request Nov 29, 2013
…ties-defaults

Adding failing test for #116 - public properties defaults are ignored
@Ocramius Ocramius merged commit 3f62454 into master Nov 29, 2013
@Ocramius Ocramius deleted the hotfix/issue-#116-public-properties-defaults branch November 29, 2013 00:01
@Ocramius Ocramius mentioned this pull request Nov 29, 2013
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants