{"action":"created","comment":{"url":"https://api.github.com/repos/Elgg/Elgg/pulls/comments/26598562","id":26598562,"diff_hunk":"@@ -235,3 +235,49 @@ Parameters:\n -  **$value** The initial value of the plugin hook.\n \n .. warning:: The `$params` and `$value` arguments are reversed between the plugin hook handlers and trigger functions!\n+\n+\n+Unregister Event/Hook Handlers\n+------------------------------\n+\n+The functions ``elgg_unregister_event_handler`` and ``elgg_unregister_plugin_hook_handler`` can be used to remove\n+handlers already registered by another plugin or Elgg core. The parameters are in the same order as the registration\n+functions, except there's no priority parameter.\n+\n+.. code:: php\n+\n+    elgg_unregister_event_handler('login', 'user', 'myPlugin_handle_login');\n+\n+When anonymous functions, dynamic methods, or invokable objects are used as event/hook handlers, the code needing\n+to unregister these handlers rarely has access to object references to build a matching callback. For these cases,\n+use an ``Elgg\\CallableMatcher`` object in place of the 3rd parameter. This class offers a flexible specification\n+string that allows matching these values without object references.\n+\n+.. code:: php\n+\n+    $obj = new MyPlugin\\Handlers();\n+    elgg_register_plugin_hook_handler('foo', 'bar', [$obj, 'handleFoo']);\n+\n+    // ... elsewhere\n+\n+    $matcher = new Elgg\\CallableMatcher('MyPlugin\\Handlers->handleFoo');\n+    elgg_unregister_plugin_hook_handler('foo', 'bar', $matcher);\n+\n+Since anonymous functions have no identifiable names, you must match purely based on the file and line numbers.\n+Since this may change over time, it's recommended to verify that the unregister function returned ``true``.\n+\n+.. code:: php\n+\n+    elgg_register_plugin_hook_handler('foo', 'bar', function ($hook, $type, $value, $params) {\n+        return 42;\n+\n+    }); // line 123 of mod/my_plugin/start.php\n+\n+    // ... elsewhere\n+\n+    // we match a function that ends between lines 115 and 125:\n+    $matcher = new Elgg\\CallableMatcher('function /mod/myplugin/start.php:120+-5');","path":"docs/design/events.rst","position":45,"original_position":45,"commit_id":"1aa69790df1605837ac12961c4160c96ec224d4a","original_commit_id":"1aa69790df1605837ac12961c4160c96ec224d4a","user":{"login":"ewinslow","id":356564,"avatar_url":"https://avatars.githubusercontent.com/u/356564?v=3","gravatar_id":"","url":"https://api.github.com/users/ewinslow","html_url":"https://github.com/ewinslow","followers_url":"https://api.github.com/users/ewinslow/followers","following_url":"https://api.github.com/users/ewinslow/following{/other_user}","gists_url":"https://api.github.com/users/ewinslow/gists{/gist_id}","starred_url":"https://api.github.com/users/ewinslow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewinslow/subscriptions","organizations_url":"https://api.github.com/users/ewinslow/orgs","repos_url":"https://api.github.com/users/ewinslow/repos","events_url":"https://api.github.com/users/ewinslow/events{/privacy}","received_events_url":"https://api.github.com/users/ewinslow/received_events","type":"User","site_admin":false},"body":"Just make people use a class instead:\r\n\r\n```php\r\nclass MyPlugin\\User\\Login {\r\n  public function __invoke($e, $t, \\ElggUser $user) {\r\n    // logic\r\n  }\r\n}\r\nelgg_register_event_handler('login', 'user', Login::class, 100);\r\n\r\nelgg_unregister_event_handler('login', 'user', MyPlugin\\User\\Login::class);\r\n```\r\n\r\nMy basic understanding of the situation is:\r\n\r\n * anonymous functions cannot be unregistered without adding extra API\r\n * the possible APIs for anonymous functions are either:\r\n   * so painful that we can't justify introducing them, or\r\n   * require extra work on the part of the plugin dev such that they might as well not use anonymous functions in the first place","created_at":"2015-03-17T18:00:31Z","updated_at":"2015-03-17T18:00:31Z","html_url":"https://github.com/Elgg/Elgg/pull/8071#discussion_r26598562","pull_request_url":"https://api.github.com/repos/Elgg/Elgg/pulls/8071","_links":{"self":{"href":"https://api.github.com/repos/Elgg/Elgg/pulls/comments/26598562"},"html":{"href":"https://github.com/Elgg/Elgg/pull/8071#discussion_r26598562"},"pull_request":{"href":"https://api.github.com/repos/Elgg/Elgg/pulls/8071"}}},"pull_request":{"url":"https://api.github.com/repos/Elgg/Elgg/pulls/8071","id":31295431,"html_url":"https://github.com/Elgg/Elgg/pull/8071","diff_url":"https://github.com/Elgg/Elgg/pull/8071.diff","patch_url":"https://github.com/Elgg/Elgg/pull/8071.patch","issue_url":"https://api.github.com/repos/Elgg/Elgg/issues/8071","number":8071,"state":"open","locked":false,"title":"feature(events): allows wider variety of callables to be unregistered","user":{"login":"mrclay","id":170687,"avatar_url":"https://avatars.githubusercontent.com/u/170687?v=3","gravatar_id":"","url":"https://api.github.com/users/mrclay","html_url":"https://github.com/mrclay","followers_url":"https://api.github.com/users/mrclay/followers","following_url":"https://api.github.com/users/mrclay/following{/other_user}","gists_url":"https://api.github.com/users/mrclay/gists{/gist_id}","starred_url":"https://api.github.com/users/mrclay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrclay/subscriptions","organizations_url":"https://api.github.com/users/mrclay/orgs","repos_url":"https://api.github.com/users/mrclay/repos","events_url":"https://api.github.com/users/mrclay/events{/privacy}","received_events_url":"https://api.github.com/users/mrclay/received_events","type":"User","site_admin":false},"body":"This adds a class usable for matching anonymous functions, dynamic method callbacks, and invokable objects without the need for an object reference. The matcher can be passed to the event/hook unregister functions to successfully remove such types of handlers.\r\n\r\nThis also renames the event registration test so it’s actively tested by PHPUnit.\r\n\r\nFixes #7750\r\nFixes #8069","created_at":"2015-03-16T23:39:26Z","updated_at":"2015-03-17T18:00:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5b5893638c613e5726aa0ee4ff74ceaccfbff0a0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Elgg/Elgg/pulls/8071/commits","review_comments_url":"https://api.github.com/repos/Elgg/Elgg/pulls/8071/comments","review_comment_url":"https://api.github.com/repos/Elgg/Elgg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Elgg/Elgg/issues/8071/comments","statuses_url":"https://api.github.com/repos/Elgg/Elgg/statuses/1aa69790df1605837ac12961c4160c96ec224d4a","head":{"label":"mrclay:unregister_7750","ref":"unregister_7750","sha":"1aa69790df1605837ac12961c4160c96ec224d4a","user":{"login":"mrclay","id":170687,"avatar_url":"https://avatars.githubusercontent.com/u/170687?v=3","gravatar_id":"","url":"https://api.github.com/users/mrclay","html_url":"https://github.com/mrclay","followers_url":"https://api.github.com/users/mrclay/followers","following_url":"https://api.github.com/users/mrclay/following{/other_user}","gists_url":"https://api.github.com/users/mrclay/gists{/gist_id}","starred_url":"https://api.github.com/users/mrclay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrclay/subscriptions","organizations_url":"https://api.github.com/users/mrclay/orgs","repos_url":"https://api.github.com/users/mrclay/repos","events_url":"https://api.github.com/users/mrclay/events{/privacy}","received_events_url":"https://api.github.com/users/mrclay/received_events","type":"User","site_admin":false},"repo":{"id":2142685,"name":"Elgg-leaf","full_name":"mrclay/Elgg-leaf","owner":{"login":"mrclay","id":170687,"avatar_url":"https://avatars.githubusercontent.com/u/170687?v=3","gravatar_id":"","url":"https://api.github.com/users/mrclay","html_url":"https://github.com/mrclay","followers_url":"https://api.github.com/users/mrclay/followers","following_url":"https://api.github.com/users/mrclay/following{/other_user}","gists_url":"https://api.github.com/users/mrclay/gists{/gist_id}","starred_url":"https://api.github.com/users/mrclay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrclay/subscriptions","organizations_url":"https://api.github.com/users/mrclay/orgs","repos_url":"https://api.github.com/users/mrclay/repos","events_url":"https://api.github.com/users/mrclay/events{/privacy}","received_events_url":"https://api.github.com/users/mrclay/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mrclay/Elgg-leaf","description":"A social networking engine","fork":true,"url":"https://api.github.com/repos/mrclay/Elgg-leaf","forks_url":"https://api.github.com/repos/mrclay/Elgg-leaf/forks","keys_url":"https://api.github.com/repos/mrclay/Elgg-leaf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mrclay/Elgg-leaf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mrclay/Elgg-leaf/teams","hooks_url":"https://api.github.com/repos/mrclay/Elgg-leaf/hooks","issue_events_url":"https://api.github.com/repos/mrclay/Elgg-leaf/issues/events{/number}","events_url":"https://api.github.com/repos/mrclay/Elgg-leaf/events","assignees_url":"https://api.github.com/repos/mrclay/Elgg-leaf/assignees{/user}","branches_url":"https://api.github.com/repos/mrclay/Elgg-leaf/branches{/branch}","tags_url":"https://api.github.com/repos/mrclay/Elgg-leaf/tags","blobs_url":"https://api.github.com/repos/mrclay/Elgg-leaf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mrclay/Elgg-leaf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mrclay/Elgg-leaf/git/refs{/sha}","trees_url":"https://api.github.com/repos/mrclay/Elgg-leaf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mrclay/Elgg-leaf/statuses/{sha}","languages_url":"https://api.github.com/repos/mrclay/Elgg-leaf/languages","stargazers_url":"https://api.github.com/repos/mrclay/Elgg-leaf/stargazers","contributors_url":"https://api.github.com/repos/mrclay/Elgg-leaf/contributors","subscribers_url":"https://api.github.com/repos/mrclay/Elgg-leaf/subscribers","subscription_url":"https://api.github.com/repos/mrclay/Elgg-leaf/subscription","commits_url":"https://api.github.com/repos/mrclay/Elgg-leaf/commits{/sha}","git_commits_url":"https://api.github.com/repos/mrclay/Elgg-leaf/git/commits{/sha}","comments_url":"https://api.github.com/repos/mrclay/Elgg-leaf/comments{/number}","issue_comment_url":"https://api.github.com/repos/mrclay/Elgg-leaf/issues/comments{/number}","contents_url":"https://api.github.com/repos/mrclay/Elgg-leaf/contents/{+path}","compare_url":"https://api.github.com/repos/mrclay/Elgg-leaf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mrclay/Elgg-leaf/merges","archive_url":"https://api.github.com/repos/mrclay/Elgg-leaf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mrclay/Elgg-leaf/downloads","issues_url":"https://api.github.com/repos/mrclay/Elgg-leaf/issues{/number}","pulls_url":"https://api.github.com/repos/mrclay/Elgg-leaf/pulls{/number}","milestones_url":"https://api.github.com/repos/mrclay/Elgg-leaf/milestones{/number}","notifications_url":"https://api.github.com/repos/mrclay/Elgg-leaf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mrclay/Elgg-leaf/labels{/name}","releases_url":"https://api.github.com/repos/mrclay/Elgg-leaf/releases{/id}","created_at":"2011-08-02T13:45:11Z","updated_at":"2014-06-24T23:34:38Z","pushed_at":"2015-03-16T23:38:27Z","git_url":"git://github.com/mrclay/Elgg-leaf.git","ssh_url":"git@github.com:mrclay/Elgg-leaf.git","clone_url":"https://github.com/mrclay/Elgg-leaf.git","svn_url":"https://github.com/mrclay/Elgg-leaf","homepage":"http://elgg.org","size":40851,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"Elgg:1.x","ref":"1.x","sha":"ec4ac7c9cead519b9d3163d23e16109f4a02ba5c","user":{"login":"Elgg","id":79167,"avatar_url":"https://avatars.githubusercontent.com/u/79167?v=3","gravatar_id":"","url":"https://api.github.com/users/Elgg","html_url":"https://github.com/Elgg","followers_url":"https://api.github.com/users/Elgg/followers","following_url":"https://api.github.com/users/Elgg/following{/other_user}","gists_url":"https://api.github.com/users/Elgg/gists{/gist_id}","starred_url":"https://api.github.com/users/Elgg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Elgg/subscriptions","organizations_url":"https://api.github.com/users/Elgg/orgs","repos_url":"https://api.github.com/users/Elgg/repos","events_url":"https://api.github.com/users/Elgg/events{/privacy}","received_events_url":"https://api.github.com/users/Elgg/received_events","type":"Organization","site_admin":false},"repo":{"id":299271,"name":"Elgg","full_name":"Elgg/Elgg","owner":{"login":"Elgg","id":79167,"avatar_url":"https://avatars.githubusercontent.com/u/79167?v=3","gravatar_id":"","url":"https://api.github.com/users/Elgg","html_url":"https://github.com/Elgg","followers_url":"https://api.github.com/users/Elgg/followers","following_url":"https://api.github.com/users/Elgg/following{/other_user}","gists_url":"https://api.github.com/users/Elgg/gists{/gist_id}","starred_url":"https://api.github.com/users/Elgg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Elgg/subscriptions","organizations_url":"https://api.github.com/users/Elgg/orgs","repos_url":"https://api.github.com/users/Elgg/repos","events_url":"https://api.github.com/users/Elgg/events{/privacy}","received_events_url":"https://api.github.com/users/Elgg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Elgg/Elgg","description":"A social networking engine","fork":false,"url":"https://api.github.com/repos/Elgg/Elgg","forks_url":"https://api.github.com/repos/Elgg/Elgg/forks","keys_url":"https://api.github.com/repos/Elgg/Elgg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Elgg/Elgg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Elgg/Elgg/teams","hooks_url":"https://api.github.com/repos/Elgg/Elgg/hooks","issue_events_url":"https://api.github.com/repos/Elgg/Elgg/issues/events{/number}","events_url":"https://api.github.com/repos/Elgg/Elgg/events","assignees_url":"https://api.github.com/repos/Elgg/Elgg/assignees{/user}","branches_url":"https://api.github.com/repos/Elgg/Elgg/branches{/branch}","tags_url":"https://api.github.com/repos/Elgg/Elgg/tags","blobs_url":"https://api.github.com/repos/Elgg/Elgg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Elgg/Elgg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Elgg/Elgg/git/refs{/sha}","trees_url":"https://api.github.com/repos/Elgg/Elgg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Elgg/Elgg/statuses/{sha}","languages_url":"https://api.github.com/repos/Elgg/Elgg/languages","stargazers_url":"https://api.github.com/repos/Elgg/Elgg/stargazers","contributors_url":"https://api.github.com/repos/Elgg/Elgg/contributors","subscribers_url":"https://api.github.com/repos/Elgg/Elgg/subscribers","subscription_url":"https://api.github.com/repos/Elgg/Elgg/subscription","commits_url":"https://api.github.com/repos/Elgg/Elgg/commits{/sha}","git_commits_url":"https://api.github.com/repos/Elgg/Elgg/git/commits{/sha}","comments_url":"https://api.github.com/repos/Elgg/Elgg/comments{/number}","issue_comment_url":"https://api.github.com/repos/Elgg/Elgg/issues/comments{/number}","contents_url":"https://api.github.com/repos/Elgg/Elgg/contents/{+path}","compare_url":"https://api.github.com/repos/Elgg/Elgg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Elgg/Elgg/merges","archive_url":"https://api.github.com/repos/Elgg/Elgg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Elgg/Elgg/downloads","issues_url":"https://api.github.com/repos/Elgg/Elgg/issues{/number}","pulls_url":"https://api.github.com/repos/Elgg/Elgg/pulls{/number}","milestones_url":"https://api.github.com/repos/Elgg/Elgg/milestones{/number}","notifications_url":"https://api.github.com/repos/Elgg/Elgg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Elgg/Elgg/labels{/name}","releases_url":"https://api.github.com/repos/Elgg/Elgg/releases{/id}","created_at":"2009-09-06T17:10:11Z","updated_at":"2015-03-17T01:13:00Z","pushed_at":"2015-03-16T14:19:13Z","git_url":"git://github.com/Elgg/Elgg.git","ssh_url":"git@github.com:Elgg/Elgg.git","clone_url":"https://github.com/Elgg/Elgg.git","svn_url":"https://github.com/Elgg/Elgg","homepage":"http://elgg.org","size":74545,"stargazers_count":686,"watchers_count":686,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":421,"mirror_url":null,"open_issues_count":749,"forks":421,"open_issues":749,"watchers":686,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Elgg/Elgg/pulls/8071"},"html":{"href":"https://github.com/Elgg/Elgg/pull/8071"},"issue":{"href":"https://api.github.com/repos/Elgg/Elgg/issues/8071"},"comments":{"href":"https://api.github.com/repos/Elgg/Elgg/issues/8071/comments"},"review_comments":{"href":"https://api.github.com/repos/Elgg/Elgg/pulls/8071/comments"},"review_comment":{"href":"https://api.github.com/repos/Elgg/Elgg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Elgg/Elgg/pulls/8071/commits"},"statuses":{"href":"https://api.github.com/repos/Elgg/Elgg/statuses/1aa69790df1605837ac12961c4160c96ec224d4a"}}}}