{"action":"opened","issue":{"url":"https://api.github.com/repos/processwire/processwire-issues/issues/109","repository_url":"https://api.github.com/repos/processwire/processwire-issues","labels_url":"https://api.github.com/repos/processwire/processwire-issues/issues/109/labels{/name}","comments_url":"https://api.github.com/repos/processwire/processwire-issues/issues/109/comments","events_url":"https://api.github.com/repos/processwire/processwire-issues/issues/109/events","html_url":"https://github.com/processwire/processwire-issues/issues/109","id":193374743,"number":109,"title":"Hooks on classes with a namespace that extend `Wire` not working","user":{"login":"owzim","id":1720088,"avatar_url":"https://avatars.githubusercontent.com/u/1720088?v=3","gravatar_id":"","url":"https://api.github.com/users/owzim","html_url":"https://github.com/owzim","followers_url":"https://api.github.com/users/owzim/followers","following_url":"https://api.github.com/users/owzim/following{/other_user}","gists_url":"https://api.github.com/users/owzim/gists{/gist_id}","starred_url":"https://api.github.com/users/owzim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owzim/subscriptions","organizations_url":"https://api.github.com/users/owzim/orgs","repos_url":"https://api.github.com/users/owzim/repos","events_url":"https://api.github.com/users/owzim/events{/privacy}","received_events_url":"https://api.github.com/users/owzim/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-04T20:51:24Z","updated_at":"2016-12-04T20:51:24Z","closed_at":null,"body":"### Short description of the issue\r\n\r\nHooks on classes with a namespace that extend `Wire` are not working.\r\n\r\n### Expected behavior\r\n\r\n```php\r\n$wire->addHookAfter('Foo\\Bar::baz', null, function($e) {\r\n    $e->return = 'qux from hook';\r\n});\r\n\r\n$bar = new \\Foo\\Bar();\r\n\r\n// should return 'qux from hook'\r\n$bar->baz();\r\n```\r\n\r\n### Actual behavior\r\n\r\nHooked method does not work, the original method value is returned. Tested with a class without namespaces, works there.\r\n\r\nNote: `$wire->addHookAfter('\\Foo\\Bar::baz', null, function)` with leading backslash is not working neither.\r\n\r\n### Screenshots/Links that demonstrate the issue\r\n\r\n![screen shot 2016-12-04 at 21 31 03](https://cloud.githubusercontent.com/assets/1720088/20868977/fee3b14c-ba68-11e6-9b70-f7c8352f4b6f.png)\r\n\r\n### Steps to reproduce the issue\r\n\r\n1. Step 1\r\n\r\nCreate `site/templates/ClassWithNameSpace.php` with the following content:\r\n\r\n```php\r\n<?php\r\nnamespace Foo;\r\nuse \\ProcessWire\\Wire;\r\n\r\nclass Bar extends Wire\r\n{\r\n    public function ___baz()\r\n    {\r\n        return 'qux';\r\n    }\r\n}\r\n```\r\n\r\n2. Step 2\r\n\r\nin `admin.php` prepend this code:\r\n\r\n```php\r\ninclude_once __DIR__ . '/ClassWithNameSpace.php';\r\n\r\n$bar = new \\Foo\\Bar();\r\n\r\n$wire->addHook('Foo\\Bar::baz', null, function($e) {\r\n    $e->return = 'qux from hook';\r\n});\r\n\r\n$session->message('$bar->baz(): \"' . $bar->baz() . '\" should be \"qux from hook\"');\r\n```\r\n\r\n3. Step 3\r\n\r\nin `wire\\core\\WireHooks.php:167` add:\r\n\r\n```php\r\nif ($method == 'baz' && $className === 'Foo\\Bar') {\r\n    wire('session')->message('$namespace \"' . $namespace . '\"');\r\n\r\n    // results in \"Foo\\\"\r\n    wire('session')->message('$_namespace \"' . $_namespace . '\"');\r\n\r\n    // results in \"Foo\\Bar\"\r\n    wire('session')->message('$className \"' . $className . '\"');\r\n\r\n    // results in \"Foo\\Foo\\Bar\"\r\n    wire('session')->message('$_className \"' . $_className . '\" should be \"\\Foo\\Bar\"');\r\n}\r\n```\r\n\r\nSince the following statement is not true, the loop will continue and the hook will not get executed:\r\n\r\n```php\r\n// $object is instance of \"\\Foo\\Bar\", but $_className holds \"Foo\\Foo\\Bar\"\r\nif(!$object instanceof $_className && $method !== '*') {\r\n    continue;\r\n}\r\n```\r\n\r\n### Setup/Environment\r\n\r\n* ProcessWire version: 3.0.42\r\n* PHP version: 5.5.12\r\n* MySQL version: 14.14 Distrib 5.6.17\r\n"}}
{"actor":{"display_login":"owzim"}}