Is it possible to redefine a core PHP function in another namespace, like function echo?
Something like:
namespace test;
function echo($yo) {
\echo('--' . $yo);
}
echo 'lol';
I am pretty new with understanding namespace and I would like to know how far we can use it.
You cannot do this for echo
, because it's not actually a function. echo
is a "language construct" and a reserved word. You cannot name a function echo
.
For built-in functions (that are actually functions) however, what you have is right. For example:
namespace test;
function print_r($yo) {
\print_r('--' . $yo);
}
print_r('lol');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With