Skip to content

Instantly share code, notes, and snippets.

@oxyberg
Last active April 17, 2019 22:28
Show Gist options
  • Save oxyberg/5690004 to your computer and use it in GitHub Desktop.
Save oxyberg/5690004 to your computer and use it in GitHub Desktop.
The smallest PHP Hook class (Observer pattern). https://twitter.com/mvoult/status/340782689286250496
class h{private$e;function b($n,$c){$this->e[$n][]=$c;}function c($n){foreach($this->e[$n] as$c)call_user_func($c);}}
@oxyberg
Copy link
Author

oxyberg commented Jun 1, 2013

Usage:

<?php
$hook = new h; // Creating a new object for Hook class
$hook->b('hook', function () {echo 'Hello, world!';}); // Creating the new hook
$hook->c('hook'); // Triggering all hooks that named 'hook'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment