Closed
Closed
Copy link
Description
Symfony version(s) affected
6.1.2
Description
If custom encoder is used, rules when normalization is hit are different apparently. We expect no normalization happens in either environment (because our encoder doesn't need normalization).
How to reproduce
Have this encoder
final class PhpEncoder implements EncoderInterface, DecoderInterface, NormalizationAwareInterface
{
public function encode(mixed $data, string $format, array $context = []): string
{
return serialize($data);
}
public function decode(string $data, string $format, array $context = []): mixed
{
return unserialize($data);
}
public function supportsEncoding(string $format, array $context = []): bool
{
return true;
}
public function supportsDecoding(string $format, array $context = []): bool
{
return true;
}
}
then try to serialize object. In APP_ENV=prod we get serialized object as expected (starting with O:
)
O:56:"
. In APP_ENV=dev we get serialized array (unexpected) (starting with a:1:{s:
)
Possible Solution
Adjust condition at
Additional Context
We were struggling to understand why output of serialization was different between APP_ENV=dev and APP_ENV=prod. Looks like issue is that in dev environment, TraceableEncoder is used. TraceableEncoder has this defined
In APP_ENV=prod TraceableEncoder is not used, so this condition is triggered instead