Skip to content

Conversation

@lyrixx
Copy link
Member

@lyrixx lyrixx commented Dec 17, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #62694
License MIT

Not finished, obviously. But is this the way to go?

@stof
Copy link
Member

stof commented Dec 17, 2025

I don't think we should create new resource types. The existing ClassResource already used by ContainerBuilder::getReflectionClass() should be used instead.

{
$hash = hash_init('xxh128');

$ret = ($this->staticMethod)();
Copy link
Member

@stof stof Dec 17, 2025

Choose a reason for hiding this comment

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

This implementation is broken. When calling it in isFresh on an unserialized data, you cannot assume that this method still exists (and is still static). The check needs to handle gracefully the case where the code was changed (as that's precisely the use case for having such resource)

@lyrixx
Copy link
Member Author

lyrixx commented Dec 18, 2025

I don't think we should create new resource types. The existing ClassResource already used by ContainerBuilder::getReflectionClass() should be used instead.

I guess you are talking about ReflectionClassResource

It won't work though, will it? It only checks the public/protected API. Here, we must execute the method and retrieve the data.

@stof
Copy link
Member

stof commented Dec 18, 2025

ah indeed. I guess the reason why RegisterListenersPass works is because in 99.9% of cases, changing the list of subscribed events also involves adding or removing the public method being registered. But if you only change the priority, it might suffer from the same issue.

private string $hash;

/**
* @param array $staticMethod A callable represented as [className, methodName]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param array $staticMethod A callable represented as [className, methodName]
* @param array{string, string} $staticMethod A callable represented as [className, methodName]

Copy link
Member

Choose a reason for hiding this comment

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

and maybe we should even have 2 parameters instead of this array.

* @param array $staticMethod A callable represented as [className, methodName]
*/
public function __construct(
private $staticMethod,
Copy link
Member

Choose a reason for hiding this comment

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

should have an array type.


public function __toString(): string
{
return 'static_method_resource'.$this->staticMethod[0].'::'.$this->staticMethod[1];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return 'static_method_resource'.$this->staticMethod[0].'::'.$this->staticMethod[1];
return 'static_method_resource:'.$this->staticMethod[0].'::'.$this->staticMethod[1];

This will be more readable in case this is investigated, by having a delimiter before the class name.


public function __unserialize(array $data): void
{
$this->hash = array_shift($data);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using array_shift, it should access the keys in the array as __serialize returns an associative array.


$ret = ($this->staticMethod)();

if (is_iterable($ret)) {
Copy link
Member

Choose a reason for hiding this comment

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

why this special case for iterable ?
And why ignoring the keys in that iterable (which will make this unusable for RegisterListenersPass) ?

@OskarStark OskarStark changed the title [Form] Reset cache when AbstractTypeExtension::getExtendedTypes change [Form] Reset cache when AbstractTypeExtension::getExtendedTypes change Dec 18, 2025
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.

3 participants