DEV Community

Aaron Junker
Aaron Junker

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

2 2

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)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay