Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 7.0: New sniff to detect direct calls to __clone() #759

Merged
merged 1 commit into from Dec 13, 2018

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 2, 2018

Directly calling __clone is allowed

Doing calls like $obj->__clone() is now allowed. This was the only magic method that had a compile-time check preventing some calls to it, which doesn't make sense. If we allow all other magic methods to be called, there's no reason to forbid this one.

Ref: https://wiki.php.net/rfc/abstract_syntax_tree#directly_calling_clone_is_allowed

Includes unit tests.

Fixes #629

Note: PR includes minor adjustments to the PHPCompatibility native PHPCS ruleset to allow for the new docblock format as per #734. This will be further addressed in a separate PR dedicated to that issue.

@jrfnl jrfnl added this to the 9.x Next milestone Nov 2, 2018
@jrfnl jrfnl requested a review from wimg November 2, 2018 10:12
@jrfnl jrfnl force-pushed the feature/629-new-direct-calls-to-clone-sniff branch from d9734b5 to 9ef0729 Compare November 2, 2018 10:29
@jrfnl
Copy link
Member Author

jrfnl commented Nov 2, 2018

Note: the build failure is unrelated to this PR, but has to do with an upstream change - see squizlabs/PHP_CodeSniffer#1574 - for which I have a PR ready.

I will pull that PR once PR squizlabs/PHP_CodeSniffer#2215 has been merged, which fixes an oversight in the commit fixing squizlabs/PHP_CodeSniffer#1574.

> Directly calling __clone is allowed
>
> Doing calls like $obj->__clone() is now allowed. This was the only magic method that had a compile-time check preventing some calls to it, which doesn't make sense. If we allow all other magic methods to be called, there's no reason to forbid this one.

Ref: https://wiki.php.net/rfc/abstract_syntax_tree#directly_calling_clone_is_allowed

Includes unit tests.

Fixes 629

Note: PR includes minor adjustments to the PHPCompatibility native PHPCS ruleset to allow for the new docblock format as per 734. This will be further addressed in a separate PR dedicated to that issue.
@jrfnl jrfnl force-pushed the feature/629-new-direct-calls-to-clone-sniff branch from 9ef0729 to 88ffb64 Compare December 9, 2018 07:46
@jrfnl
Copy link
Member Author

jrfnl commented Dec 9, 2018

Rebased. Build should now be able to pass.

@jrfnl jrfnl changed the title PHP 7.0: new sniff to detect direct calls to __clone() PHP 7.0: New sniff to detect direct calls to __clone() Dec 9, 2018
@wimg wimg merged commit 121701a into master Dec 13, 2018
@wimg wimg deleted the feature/629-new-direct-calls-to-clone-sniff branch December 13, 2018 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP 7.0: detect direct calls to __clone() magic method
2 participants