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

Add native types to reflection property classes #9631

Merged
merged 1 commit into from May 11, 2022

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Apr 5, 2022

No description provided.

@derrabus derrabus added this to the 3.0.0 milestone Apr 5, 2022
use ValueError;

use function array_map;
use function get_class;
use function is_array;

class ReflectionEnumProperty extends ReflectionProperty
final class ReflectionEnumProperty extends ReflectionProperty
Copy link
Member Author

Choose a reason for hiding this comment

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

I've finalized the classes because they extend built-in classes. If the signatures change upstream, maintaining BC for child classes is going to be a nightmare.

Copy link
Member

@greg0ire greg0ire May 11, 2022

Choose a reason for hiding this comment

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

Should we at some point generate a list of finalized classes, then add an @final annotation on every such class on 2.x?

@derrabus derrabus force-pushed the types/reflection-properties branch from ecf2474 to 0bbf53b Compare April 22, 2022 18:15
@@ -68,7 +53,7 @@ public function getValue($object = null)
* @param object $object
* @param int|string|int[]|string[]|null $value
*/
public function setValue($object, $value = null): void
public function setValue(mixed $object, mixed $value = null): void
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't mixed $value break with the getValue method return type?

Copy link
Member Author

@derrabus derrabus Apr 24, 2022

Choose a reason for hiding this comment

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

setValue() is inherited from ReflectionProperty which declares mixed as parameter type already. I'm only allowed to make parameter types wider when overriding and it can't get wider than mixed. So mixed is actually the only possible native type here.

Copy link
Member

Choose a reason for hiding this comment

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

Then I would expect getValue() to return mixed too. https://www.php.net/manual/en/reflectionproperty.getvalue.php

If any value is set that is not part of int|string|array|null, then we'll have a TypeError.

Copy link
Member Author

Choose a reason for hiding this comment

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

If any value is set that is not part of int|string|array|null, then we'll have a TypeError.

No, $enum->value would crash before that. Our implementation of getValue() can only return int|string|array|null, we can be sure about that.

Note, I'm declaring the parameter type as mixed because of a technical limitation which is PHP not supporting generics natively. The doc block is more precise in that regard.

@derrabus derrabus force-pushed the types/reflection-properties branch from 0bbf53b to d9d2bda Compare April 27, 2022 11:52
@derrabus derrabus requested a review from greg0ire May 11, 2022 09:46
use ValueError;

use function array_map;
use function get_class;
use function is_array;

class ReflectionEnumProperty extends ReflectionProperty
final class ReflectionEnumProperty extends ReflectionProperty
Copy link
Member

@greg0ire greg0ire May 11, 2022

Choose a reason for hiding this comment

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

Should we at some point generate a list of finalized classes, then add an @final annotation on every such class on 2.x?

@derrabus derrabus merged commit d294e1d into doctrine:3.0.x May 11, 2022
@derrabus derrabus deleted the types/reflection-properties branch May 11, 2022 18:34
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.

None yet

3 participants