{"id":16511140,"url":"https://github.com/danog/magicalserializer","last_synced_at":"2025-07-08T01:42:02.397Z","repository":{"id":56962168,"uuid":"89863282","full_name":"danog/MagicalSerializer","owner":"danog","description":"Serialize internal PHP objects!","archived":false,"fork":false,"pushed_at":"2018-04-27T16:42:39.000Z","size":35,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-01T04:31:39.448Z","etag":null,"topics":["php","pthreads","serializable-objects","serialization","threading","volatile"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-30T16:39:40.000Z","updated_at":"2023-02-01T23:23:33.000Z","dependencies_parsed_at":"2022-08-21T05:40:16.993Z","dependency_job_id":null,"html_url":"https://github.com/danog/MagicalSerializer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2FMagicalSerializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2FMagicalSerializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2FMagicalSerializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2FMagicalSerializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danog","download_url":"https://codeload.github.com/danog/MagicalSerializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244765047,"owners_count":20506750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","pthreads","serializable-objects","serialization","threading","volatile"],"created_at":"2024-10-11T15:59:06.515Z","updated_at":"2025-03-21T08:31:23.808Z","avatar_url":"https://github.com/danog.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MagicalSerializer\n\nLicensed under AGLPV3, created by Daniil Gentili (https://daniil.it).\n\nThis library allows you to serialize classes that extend pthreads's Volatile or Threaded classes, or any other internal class with a custom serializer.  \n\nIt also provides reverse and forward compatibility between old serializations, where your objects do not yet extend Threaded/Volatile, and new serializations, where they do extend them.\n\nInstall it using composer, the package name is `danog/magicalserializer`.\n\n\nUsage of this library is extremely simple, here are a few examples (see a.php and b.php for more):\n\n\n```\n\u003c?php\n\nclass a\n{\n    public function __construct() {\n        var_dump(\"Constructed!\");\n        $this-\u003ea = 'pony';\n    }\n    public function __wakeup() {\n        var_dump($this-\u003ea);\n    }\n}\n$a = new a;\nfile_put_contents('test', serialize($a));\n```\n\nAs you can see, here `a` does not extend any class, and we are serializing an instance of it to the file `test`.\nThis example also prints `Constructed!`, since the constructor function, `__magic_construct`, is called.\n\n```\n\u003c?php\n\nclass a extends \\Volatile\n{\n    use \\danog\\Serializable;\n    public function __magic_construct() {\n        var_dump(\"Constructed!\");\n        $this-\u003ea = 'pony';\n    }\n    public function __wakeup() {\n        var_dump($this-\u003ea);\n    }\n}\n$a = \\danog\\Serialization::unserialize(file_get_contents('test'));\nvar_dump($a);\n$othera = new a;\n\n```\n\nHere we must simply include the trait `\\danog\\Serializable` to make the class serializable.  \nThis will deserialize correctly the contents of `test`, recreating the instance of `a`, with the only difference that now it will be thread safe.  \nOf course, the wakeup function will be called, so `pony` will be printed.  \nYou may have noticed that the construct function is now called `__magic_construct` instead of `__construct`: this is a required change, or else this library will not work.  \nOf course, when `a` will be instantiated, the constructor function will be called anyway (and you'll see the message `Constructed!` pop up).  \n\nIf you try to serialize (using `\\danog\\Serialization::serialize`) either `$a` or `$othera` and deserialize it from the first script (where `a` does not extend any other class), you will find that it will be deserialized correctly.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanog%2Fmagicalserializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanog%2Fmagicalserializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanog%2Fmagicalserializer/lists"}