You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-9Lines changed: 25 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -172,21 +172,37 @@ Action::initialize();
172
172
See [examples/class_static_construct.php](examples/class_static_construct.php) for example to overcome this limitation.
173
173
174
174
### Serialization
175
-
There no possibility to serialize the singleton. As a result, we have to restrict direct Enum object serialization.
176
-
[New custom object serialization mechanism](https://wiki.php.net/rfc/custom_object_serialization) does not help with direct Enum serialization
177
-
but it give the possibility to control this in class which hold the reference to Enums instances. Also, it can be workaround
178
-
with [Serializable Interface](https://www.php.net/manual/en/class.serializable.php) in similar way. So this problem somehow
179
-
solves with worse developer experience. [TODO: clarify] Probably, [similar to Java Enums](https://stackoverflow.com/questions/15521309/is-custom-enum-serializable-too)
180
-
the PHP Enums should not be serializable at all. The only way to serialize the Enum is to obtain the name of Enum constant
181
-
and use valueOf() method to obtain the Enum constant.
175
+
There no possibility to serialize the singleton. As a result, we have to restrict direct Enum object serialization.
182
176
```php
183
177
<?php
184
178
// Following line will throw an exception
185
179
serialize(Action::$view);
186
180
```
187
-
See [examples/serialization_php74.php](examples/serialization_php74.php) to overcome this limitation.
188
-
It is possible to submit RFC to implement singleton serialization in PHP. For example [Java Enums](https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html)
181
+
[New custom object serialization mechanism](https://wiki.php.net/rfc/custom_object_serialization) does not help with singleton serialization
182
+
but it give the possibility to control this in class which hold the reference to Enums instances. Also, it can be workaround
183
+
with [Serializable Interface](https://www.php.net/manual/en/class.serializable.php) in similar way.
184
+
[Similar to Java Enums](https://stackoverflow.com/a/15522276/983577)
185
+
the PHP Enumeration Class serialized differently. For example [Java Enums](https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html)
189
186
implements Serializable interface and replace class instance during unserialization in [readResolve()](https://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html) method.
187
+
In PHP, serialize the name of Enum constant and use valueOf() method to obtain the Enum constant value during unserialization.
188
+
So this problem somehow solves with worse developer experience. Hope it will be solved in in future RFCs.
0 commit comments