{"action":"created","issue":{"url":"https://api.github.com/repos/marc-mabe/php-enum/issues/76","repository_url":"https://api.github.com/repos/marc-mabe/php-enum","labels_url":"https://api.github.com/repos/marc-mabe/php-enum/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/marc-mabe/php-enum/issues/76/comments","events_url":"https://api.github.com/repos/marc-mabe/php-enum/issues/76/events","html_url":"https://github.com/marc-mabe/php-enum/issues/76","id":187345734,"number":76,"title":"unserialize can only work once","user":{"login":"delbertooo","id":923638,"avatar_url":"https://avatars.githubusercontent.com/u/923638?v=3","gravatar_id":"","url":"https://api.github.com/users/delbertooo","html_url":"https://github.com/delbertooo","followers_url":"https://api.github.com/users/delbertooo/followers","following_url":"https://api.github.com/users/delbertooo/following{/other_user}","gists_url":"https://api.github.com/users/delbertooo/gists{/gist_id}","starred_url":"https://api.github.com/users/delbertooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delbertooo/subscriptions","organizations_url":"https://api.github.com/users/delbertooo/orgs","repos_url":"https://api.github.com/users/delbertooo/repos","events_url":"https://api.github.com/users/delbertooo/events{/privacy}","received_events_url":"https://api.github.com/users/delbertooo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"marc-mabe","id":302689,"avatar_url":"https://avatars.githubusercontent.com/u/302689?v=3","gravatar_id":"","url":"https://api.github.com/users/marc-mabe","html_url":"https://github.com/marc-mabe","followers_url":"https://api.github.com/users/marc-mabe/followers","following_url":"https://api.github.com/users/marc-mabe/following{/other_user}","gists_url":"https://api.github.com/users/marc-mabe/gists{/gist_id}","starred_url":"https://api.github.com/users/marc-mabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marc-mabe/subscriptions","organizations_url":"https://api.github.com/users/marc-mabe/orgs","repos_url":"https://api.github.com/users/marc-mabe/repos","events_url":"https://api.github.com/users/marc-mabe/events{/privacy}","received_events_url":"https://api.github.com/users/marc-mabe/received_events","type":"User","site_admin":false},"assignees":[{"login":"marc-mabe","id":302689,"avatar_url":"https://avatars.githubusercontent.com/u/302689?v=3","gravatar_id":"","url":"https://api.github.com/users/marc-mabe","html_url":"https://github.com/marc-mabe","followers_url":"https://api.github.com/users/marc-mabe/followers","following_url":"https://api.github.com/users/marc-mabe/following{/other_user}","gists_url":"https://api.github.com/users/marc-mabe/gists{/gist_id}","starred_url":"https://api.github.com/users/marc-mabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marc-mabe/subscriptions","organizations_url":"https://api.github.com/users/marc-mabe/orgs","repos_url":"https://api.github.com/users/marc-mabe/repos","events_url":"https://api.github.com/users/marc-mabe/events{/privacy}","received_events_url":"https://api.github.com/users/marc-mabe/received_events","type":"User","site_admin":false}],"milestone":null,"comments":7,"created_at":"2016-11-04T14:22:12Z","updated_at":"2016-12-04T19:21:54Z","closed_at":null,"body":"The so called \"magic\" from EnumSerializableTrait can only work once. If unserialize is called more than one time, it can't be compared by reference anymore.\r\n\r\nThis isn't your fault at all. It's just not possible to build this in php right now.\r\n\r\nIMO the serializable support should be entirely dropped. It has so many possabilities to create side effects and nearly no safe usages. The enums should throw errors if serialized / unserialized. Maybe there could be a serializable enum class, which isn't comparable via reference.\r\n\r\n## How to reproduce\r\n\r\n    From 7899614f0dc543e3ad2f3f2304d2ed257d7bc7b6 Mon Sep 17 00:00:00 2001\r\n    From: Robert Worgul <robert.worgul@scitotec.de>\r\n    Date: Fri, 4 Nov 2016 15:10:33 +0100\r\n    Subject: [PATCH] test unserialize works multiple times\r\n    \r\n    ---\r\n     tests/MabeEnumTest/EnumSerializableTraitTest.php | 3 +++\r\n     1 file changed, 3 insertions(+)\r\n    \r\n    diff --git a/tests/MabeEnumTest/EnumSerializableTraitTest.php b/tests/MabeEnumTest/EnumSerializableTraitTest.php\r\n    index 65e6280..01ce977 100644\r\n    --- a/tests/MabeEnumTest/EnumSerializableTraitTest.php\r\n    +++ b/tests/MabeEnumTest/EnumSerializableTraitTest.php\r\n    @@ -49,6 +49,9 @@ class EnumSerializableTraitTest extends TestCase\r\n    \r\n             // check if it's the same instance\r\n             $this->assertSame($enum, $unserialized);\r\n    +\r\n    +        $unserialized2 = unserialize($serialized);\r\n    +        $this->assertSame($enum, $unserialized2);\r\n         }\r\n    \r\n         public function testUnserializeThrowsRuntimeExceptionOnUnknownValue()\r\n    --\r\n    2.7.4\r\n"},"comment":{"url":"https://api.github.com/repos/marc-mabe/php-enum/issues/comments/264724453","html_url":"https://github.com/marc-mabe/php-enum/issues/76#issuecomment-264724453","issue_url":"https://api.github.com/repos/marc-mabe/php-enum/issues/76","id":264724453,"user":{"login":"marc-mabe","id":302689,"avatar_url":"https://avatars.githubusercontent.com/u/302689?v=3","gravatar_id":"","url":"https://api.github.com/users/marc-mabe","html_url":"https://github.com/marc-mabe","followers_url":"https://api.github.com/users/marc-mabe/followers","following_url":"https://api.github.com/users/marc-mabe/following{/other_user}","gists_url":"https://api.github.com/users/marc-mabe/gists{/gist_id}","starred_url":"https://api.github.com/users/marc-mabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marc-mabe/subscriptions","organizations_url":"https://api.github.com/users/marc-mabe/orgs","repos_url":"https://api.github.com/users/marc-mabe/repos","events_url":"https://api.github.com/users/marc-mabe/events{/privacy}","received_events_url":"https://api.github.com/users/marc-mabe/received_events","type":"User","site_admin":false},"created_at":"2016-12-04T19:21:54Z","updated_at":"2016-12-04T19:21:54Z","body":"@delbertooo First of all this library adds **virtual** enumeration support to PHP because PHP doesn't have it as a real build-in feature. That of course means that this library is limited.\r\n\r\nWe are trying your best to make it as close to real enumerations as possible!\r\n\r\n> My tought for a serializable enum class was some kind of equals method, like Java\r\n\r\nThis is something we have already. It's called `Enum::is()` and I added a PR to accept two different enumerator instances of the exact same thing. see #77 \r\n\r\nInterestingly also in Java enumerations are singletons. I'm not a Java developer but because of this the equal operator should work in Java, too. I have no idea if Java would have the same issue if you serialize and unserialize an enumerations.\r\n\r\n> In my opinion it would be better to generally drop the reference equality for serializable enums. It would be a documented \"feature\" that a serializable enum can never be compared to an enum or serializable enum via == or ===. Each serializable enum would be a new instance.\r\n\r\nIt doesn't make sense to change the general singleton behavior only because it's implementing `Serializable` interface. That would mean your question is for removing the singleton in general where you get a big no from me.\r\n\r\nAlso not injecting an unserialized enumeration in general does not make sense to me because later in your code has absolutely no logic about where objects are coming from. That's the reason why I try to reduce the behavior of having two different instances of the same enumerators as much as I can. In this case it's only possible once but it's still better then ńever.\r\n\r\nAnd again with #77 you can surely use `Enum::is()` to check for identical enumerators safely."}}
{"actor":{"display_login":"marc-mabe"}}