Cancelling Native Function

../_images/cancelling_native_function.png

PHP native functions are part of the global scope. In a custom namespace, the local definition of a function has priority. And when this fails, PHP fallbacks to the global space. This is a backward compatibility process, that prevents developer from adding ALL native PHP functions as a use expression in every file. This would be long, boring and a performance boost.

To cancel a PHP native function, such as print_r or var_dump, the trick is to create a definition of that function in the same namespace. It is then used with precedence, and may be prevented from having any impact.

This would be different from using the disable_functions: then, the function undefined, and shall be defined again, in the global namespace, to be properly neutralized.

This trick does not work with classes.

See Also

PHP Features