DEV Community

Aaron Junker
Aaron Junker

Posted on • Updated on • Originally published at blog.aaron-junker.ch

Access overwritten built-in functions in PHP

PHP has many built in functions. Normally you can’t override them. The only exception: If you’re in another namespace. But how can you then access the real function again? Simply add a backslash before the functions name and the built-in function get called.

Example:

<?php  
    namespace test{
        function phpversion(){
            return "Not the real phpversion";
        }
        echo phpversion()."<br />";
        echo \phpversion()."<br />";
        echo phpversion()."<br />";
    }
?>
Enter fullscreen mode Exit fullscreen mode

This will output something like:

Not the real phpversion
8.0.0
Not the real phpversion

Top comments (0)