Skip to content

Commit 3aac213

Browse files
authored
Solve Cannot declare class SerializationException (#159)
Fixes #157.
1 parent ec5e326 commit 3aac213

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/Sync/functions.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
use Amp\Serialization\SerializationException as SerializerException;
66

77
if (!\class_exists(SerializationException::class)) {
8-
// Alias must be defined in an always-loaded file as catch blocks do not trigger the autoloader.
9-
\class_alias(SerializerException::class, SerializationException::class);
8+
// Wrap definition in error handler to avoid apparently PHP bug with preloading, see amphp/parallel#159
9+
set_error_handler(function (): bool { return true; });
10+
try {
11+
// Alias must be defined in an always-loaded file as catch blocks do not trigger the autoloader.
12+
\class_alias(SerializerException::class, SerializationException::class);
13+
} finally {
14+
restore_error_handler();
15+
}
1016
}
1117

1218
/**

0 commit comments

Comments
 (0)