Skip to content

Instantly share code, notes, and snippets.

@ezimuel
Last active June 12, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezimuel/ac07dd3ff4ca321b608de185c52ef3c2 to your computer and use it in GitHub Desktop.
Save ezimuel/ac07dd3ff4ca321b608de185c52ef3c2 to your computer and use it in GitHub Desktop.
Simple API for overriding functions and method of classes
<?php
// APIs for overriding functions and methods of classes
override_class_function(string $class, string $method, Closure $callback);
override_function(string $function, Closure $callback);
call_orginal_function(array $params);
// Example of usage override_function()
override_function('curl_exec', function(){
$params = func_get_args();
echo "--- BEFORE ---";
$result = call_original_function($params);
echo "--- AFTER ---";
return $result;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment