Reputation: 706
So let's say I need to call my specified function after built-in PHP date()
function is called, is it possible to do it? Can't find anything about it or I'm not able to properly search for it.
I need to work it like callback, so everytime date()
function is called my specified function should run after that also and have all those arguments that were provided to date()
function.
Any help is appreciated.
Upvotes: 0
Views: 227
Reputation: 21489
You can define alternative function _date()
that call date()
and your special function. So you use _date()
in your code instead of date()
function _date($format, $timestamp = null){
$result = !isset($timestamp) ? date($format) : date($format, $timestamp);
myFunction($format, $timestamp);
return $result;
}
function myFunction($format, $timestamp){
echo $format."/";
}
echo _date("Y-m-d");
// output: Y-m-d/2018-11-07
Check result in demo
Upvotes: 1