PHP
quick guide & examples
Hooks are mechanics to alter or change a process.
PHP does not suport hooks natively.
We can only simulate hooks in PHP.
FUNCTION WITH HOOK function save ($email) { $ok = file_put_contents("DEMO.TXT", $email); if ($ok && function_exists("after")) { $ok = after($email); } return $ok; }
HOOK - SEND EMAIL function after ($email) { return mail($email, TITLE", "MESSAGE"); }
GO! echo save ("jon@doe.com") ? "OK" : "ERR" ;
FUNCTION WITH HOOK function save ($email, $hook) { $ok = file_put_contents("DEMO.TXT", $email); if ($ok && is_callable($hook)) { $ok = $hook($email); } return $ok; }
GO! echo save ("jon@doe.com", "after") ? "OK" : "ERR" ;
HOOK - SEND EMAIL function after ($email) { return mail($email, TITLE", "MESSAGE"); }
FUNCTION WITH HOOK function save ($email, $hook) { $ok = file_put_contents("DEMO.TXT", $email); if ($ok && file_exists($hook)) { include $hook; } return $ok; }
AFTER.PHP $ok = mail($email, TITLE", "MESSAGE");
GO! echo save ("jon@doe.com", "after.php") ? "OK" : "ERR" ;