{"action":"created","issue":{"url":"https://api.github.com/repos/krakjoe/pthreads/issues/494","labels_url":"https://api.github.com/repos/krakjoe/pthreads/issues/494/labels{/name}","comments_url":"https://api.github.com/repos/krakjoe/pthreads/issues/494/comments","events_url":"https://api.github.com/repos/krakjoe/pthreads/issues/494/events","html_url":"https://github.com/krakjoe/pthreads/issues/494","id":109915157,"number":494,"title":"Damaged objects within closures","user":{"login":"SirSnyder","id":4345652,"avatar_url":"https://avatars.githubusercontent.com/u/4345652?v=3","gravatar_id":"","url":"https://api.github.com/users/SirSnyder","html_url":"https://github.com/SirSnyder","followers_url":"https://api.github.com/users/SirSnyder/followers","following_url":"https://api.github.com/users/SirSnyder/following{/other_user}","gists_url":"https://api.github.com/users/SirSnyder/gists{/gist_id}","starred_url":"https://api.github.com/users/SirSnyder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SirSnyder/subscriptions","organizations_url":"https://api.github.com/users/SirSnyder/orgs","repos_url":"https://api.github.com/users/SirSnyder/repos","events_url":"https://api.github.com/users/SirSnyder/events{/privacy}","received_events_url":"https://api.github.com/users/SirSnyder/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-10-06T00:51:00Z","updated_at":"2015-10-07T17:12:26Z","closed_at":null,"body":"Hi @krakjoe, a really strange behaviour in connection with closures. Sadly I've no simple code to reproduce this bug by now. \r\n\r\nExample one(schematic representation)\r\n\r\n```\r\ninterface TestInterface {}\r\n\r\n    class DebugClass implements TestInterface {}\r\n\r\n    class SystemLoader\r\n    {\r\n        ....\r\n        public static function setupThreadContext()\r\n        {\r\n            $closure = function()\r\n            {\r\n                return new \\DebugClass();\r\n            };\r\n            $objCreated = $closure();\r\n\r\n            echo 'first outer instanceof TestInterface check: '. ($objCreated instanceof \\TestInterface ? 'true' : 'false') . PHP_EOL;\r\n\r\n            self::commonSetup();\r\n        }\r\n\r\n        protected static function commonSetup()\r\n        {\r\n            $closure = function()\r\n            {\r\n                $d = new \\DebugClass();\r\n\r\n                echo 'second inner instanceof TestInterface check: '. ($d instanceof \\TestInterface ? 'true' : 'false') . PHP_EOL;\r\n\r\n                return $d;\r\n            };\r\n            /** @var Threaded $objCreated */\r\n            $objCreated = $closure();\r\n            \r\n            $objClass = new \\ReflectionClass($objCreated);\r\n\r\n            var_dump($objClass->getInterfaceNames(), $objClass->implementsInterface(\\TestInterface::class));\r\n\r\n            echo 'second outer instanceof TestInterface check: '. ($objCreated instanceof \\TestInterface ? 'true' : 'false') . PHP_EOL;\r\n\r\n        }\r\n        ....\r\n    }\r\n\r\n    class Runtime\r\n    {\r\n        ....\r\n        public static function initThreadContext()\r\n        {\r\n            \\SystemLoader::setupThreadContext();\r\n        }\r\n        ....\r\n    }\r\n\r\n    class Test extends Thread\r\n    {\r\n        public function run()\r\n        {\r\n            \\Runtime::initThreadContext();\r\n        }\r\n    }\r\n\r\n    $t = new Test();\r\n    $t->start();\r\n    $t->join();\r\n```\r\nOutput:\r\nfirst outer instanceof TestInterface check: true\r\nsecond inner instanceof TestInterface check: true\r\narray(1) {\r\n  [0]=>\r\n  string(13) \"TestInterface\"\r\n}\r\nbool(false)  <<-- $objClass->implementsInterface(\\TestInterface::class)\r\nsecond outer instanceof TestInterface check: false\r\n\r\nExample two\r\n```\r\nclass ThreadLocalStorage\r\n{\r\n    public static function get(ThreadedObject $threaded, $name)\r\n    {\r\n         ...\r\n    }\r\n}\r\n\r\nclass ThreadedReflectionClass extends \\Threaded implements ThreadedObject\r\n    {\r\n        ...\r\n\r\n        /**\r\n         * @return \\ReflectionClass\r\n         */\r\n        protected function getReflectionClass():\\ReflectionClass\r\n        {\r\n            return $this->synchronized(function()\r\n            {\r\n                /** @var \\ReflectionClass $objReflectionClass */\r\n                $objReflectionClass = ThreadLocalStorage::get($this, self::TLS_REFLECTION_CLASS);\r\n\r\n                if($objReflectionClass === null)\r\n                {\r\n                    $objReflectionClass = new \\ReflectionClass($this->strClassname);\r\n\r\n                    ThreadLocalStorage::set($this, self::TLS_REFLECTION_CLASS, $objReflectionClass, false);\r\n                }\r\n                return $objReflectionClass;\r\n            });\r\n        }\r\n\r\n        ...\r\n    }\r\n```\r\nFatal error: Uncaught TypeError: Argument 1 passed to com\\badnoobcom\\liquid\\concurrent\\ThreadLocalStorage::get() must implement interface com\\badnoobcom\\liquid\\concurrent\\ThreadedObject, instance of com\\badnoobcom\\liquid\\concurrent\\reflection\\ThreadedReflectio\r\nnClass given, called in D:\\php\\libraries\\liquid\\src\\com\\badnoobcom\\liquid\\concurrent\\reflection\\ThreadedReflectionClass.php on line 1055 and defined in D:\\php\\libraries\\liquid\\src\\com\\badnoobcom\\liquid\\concurrent\\ThreadLocalStorage.php:193\r\n\r\nAt some point, it seems, within a closure an object instance loses the implemented interfaces? Any suggests or ideas? I'm baffled right now."},"comment":{"url":"https://api.github.com/repos/krakjoe/pthreads/issues/comments/146265196","html_url":"https://github.com/krakjoe/pthreads/issues/494#issuecomment-146265196","issue_url":"https://api.github.com/repos/krakjoe/pthreads/issues/494","id":146265196,"user":{"login":"Jan-E","id":1757825,"avatar_url":"https://avatars.githubusercontent.com/u/1757825?v=3","gravatar_id":"","url":"https://api.github.com/users/Jan-E","html_url":"https://github.com/Jan-E","followers_url":"https://api.github.com/users/Jan-E/followers","following_url":"https://api.github.com/users/Jan-E/following{/other_user}","gists_url":"https://api.github.com/users/Jan-E/gists{/gist_id}","starred_url":"https://api.github.com/users/Jan-E/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jan-E/subscriptions","organizations_url":"https://api.github.com/users/Jan-E/orgs","repos_url":"https://api.github.com/users/Jan-E/repos","events_url":"https://api.github.com/users/Jan-E/events{/privacy}","received_events_url":"https://api.github.com/users/Jan-E/received_events","type":"User","site_admin":false},"created_at":"2015-10-07T17:12:25Z","updated_at":"2015-10-07T17:12:25Z","body":"It always loaded when I did a 'php-cgi phpinfo.php'. In fact it still does in PHP 5.6.14:\r\nhttps://phpdev.toolsforresearch.com/php-5.6.14-Win32-VC11-x64.htm"}}