Skip to content

[Translator] avoid serialize unserializable resources. #14705

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
Jun 5, 2015

Conversation

aitboudad
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets #14689
Tests pass? yes
License MIT

@xabbuh
Copy link
Member

xabbuh commented May 20, 2015

@aitboudad Can we add a test for this to avoid future regressions?

@aitboudad aitboudad force-pushed the translation_serialize_fix branch from 047ec82 to 8b448dc Compare May 22, 2015 11:52
@aitboudad
Copy link
Contributor Author

@xabbuh test added.

if (isset($this->resources[$locale])) {
foreach ($this->resources[$locale] as $resource) {
if (is_object($resource[1]) && !$resource[1] instanceof \Serializable) {
$resource[1] = get_class($resource[1]);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is relevant, but if we are looking for something unique here, it might be better to use spl_object_hash($resource[1])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Me too, spl_object_hash($resource[1]) doesn't solve the issue because when object is destroyed, its hash may be changed.
I think it's better to removing that part until we found the right way ??

Copy link
Member

Choose a reason for hiding this comment

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

But using spl_object_hash is much better. The reuse for an object that is also a resource is probably a very small risk

Copy link
Member

Choose a reason for hiding this comment

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

Using spl_object_hash() means that we get different paths on each request, doesn't it?. Isn't that an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, I reverted that part as I think it should be handled by config cache instead of serializing resources.

@aitboudad aitboudad removed the Ready label May 25, 2015
@nicolas-grekas
Copy link
Member

ping @iamluc

@stof
Copy link
Member

stof commented Jun 5, 2015

👍

@fabpot
Copy link
Member

fabpot commented Jun 5, 2015

Thank you @aitboudad.

@fabpot fabpot merged commit 7220f2c into symfony:2.7 Jun 5, 2015
fabpot added a commit that referenced this pull request Jun 5, 2015
…tboudad)

This PR was merged into the 2.7 branch.

Discussion
----------

[Translator] avoid serialize unserializable resources.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Fixed tickets  | #14689
| Tests pass?   | yes
| License       | MIT

Commits
-------

7220f2c [Translator] avoid serialize unserializable resources.
@aitboudad aitboudad deleted the translation_serialize_fix branch June 5, 2015 14:26
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.

5 participants