Skip to content

[PropertyAccess] Allow to disable magic __get & __set #32133

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

Merged
merged 1 commit into from
Aug 19, 2020
Merged

[PropertyAccess] Allow to disable magic __get & __set #32133

merged 1 commit into from
Aug 19, 2020

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented Jun 21, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR TODO

Working with some legacy code having annoying __get & __set methods, this would have been useful the same way __call can be enabled/disabled.

@ogizanagi ogizanagi changed the base branch from 4.4 to master January 3, 2020 14:33
@ogizanagi
Copy link
Contributor Author

Rebased to target 5.1

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

LGTM (not sure why I didn't review this PR before).
Can you rebase on current master, fix the minor issues so that I can merge?
Thank you.

@ogizanagi
Copy link
Contributor Author

ogizanagi commented Aug 17, 2020

@fabpot No problem, done.
But I'd friendly ask @dunglas & @joelwurtz review, since the component has changed a lot since 5.1 and now relies on the PropertyInfo component. Thus, this new version of the PR also tweaks the PropertyInfo ReflectionExtractor

/** @var int Allow none of the magic methods */
public const DISALLOW_MAGIC_METHODS = ReflectionExtractor::DISALLOW_MAGIC_METHODS;
/** @var int Allow magic __get methods */
public const MAGIC_GET = ReflectionExtractor::ALLOW_MAGIC_GET;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are now aliases to the ReflectionExtractor constants, since it would be unexpected/not-discoverable for the user to use ReflectionExtractor consts to configure the accessor.

$allowMagicSet = (bool) ($magicMethods & self::ALLOW_MAGIC_SET);

if (isset($context['enable_magic_call_extraction'])) {
trigger_deprecation('symfony/property-info', '5.2', 'Using the "enable_magic_call_extraction" context option in "%s()" is deprecated. Use "enable_magic_methods_extraction" instead.', __METHOD__);
Copy link
Contributor Author

@ogizanagi ogizanagi Aug 17, 2020

Choose a reason for hiding this comment

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

Other options are keeping this key and have enable_magic_get_extraction / enable_magic_set_extraction context keys as well and either:

  • have 3 new constructor arguments for the default
  • or keep a single constructor arguments with flags (but still have dedicated context keys).

@@ -73,14 +83,15 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
* @param string[]|null $accessorPrefixes
* @param string[]|null $arrayMutatorPrefixes
*/
public function __construct(array $mutatorPrefixes = null, array $accessorPrefixes = null, array $arrayMutatorPrefixes = null, bool $enableConstructorExtraction = true, int $accessFlags = self::ALLOW_PUBLIC, InflectorInterface $inflector = null)
public function __construct(array $mutatorPrefixes = null, array $accessorPrefixes = null, array $arrayMutatorPrefixes = null, bool $enableConstructorExtraction = true, int $accessFlags = self::ALLOW_PUBLIC, InflectorInterface $inflector = null, int $magicMethodsFlags = self::ALLOW_MAGIC_GET | self::ALLOW_MAGIC_SET)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The magicMethodsFlags defaults are configured here for BC with 5.1, but before 5.1, magic get and set weren't supported, right?
So should it have been considered a BC break to enable them by default on 5.1?

Copy link
Member

Choose a reason for hiding this comment

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

@ogizanagi Yes, this looks like a BC break to me. I think we need to set the default value to ReflectionExtractor::DISALLOW_MAGIC_METHODS. We can consider deprecating this default value, but I am not convinced that's really necessary.

fabpot added a commit that referenced this pull request Aug 19, 2020
…zanagi)

This PR was merged into the 5.1 branch.

Discussion
----------

[PropertyInfo] Fix ReflectionExtractor + minor tweaks

| Q             | A
| ------------- | ---
| Branch?       | 5.1 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | N/A

Spotted while rebasing #32133

Commits
-------

7ccb5a1 [PropertyInfo] Fix ReflectionExtractor + minor tweaks
@fabpot
Copy link
Member

fabpot commented Aug 19, 2020

#37857 has been merged up to master, you can rebase now.

@ogizanagi
Copy link
Contributor Author

fabbot failure is unrelated to this PR

@fabpot
Copy link
Member

fabpot commented Aug 19, 2020

Thank you @ogizanagi.

@ogizanagi ogizanagi deleted the feature/property-access/disable-magic-get-set branch August 19, 2020 17:18
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@fabpot fabpot mentioned this pull request Oct 5, 2020
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Mar 9, 2021
…abbuh)

This PR was merged into the 5.2 branch.

Discussion
----------

[PropertyAccess] use bitwise instead of boolean flags

see symfony/symfony#32133

Commits
-------

c5101c7 [PropertyAccess] use bitwise instead of boolean flags
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.

6 participants