Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redefine core function in another namespace

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.

like image 305
Alexandre Avatar asked Nov 07 '13 20:11

Alexandre


1 Answers

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');
like image 159
Rocket Hazmat Avatar answered Oct 26 '22 23:10

Rocket Hazmat