phpnamespacesname-collision

PHP namespaced function collision


I use a namespace.

I have a function that has the same name as a native PHP function.

The issue is not that I create a function with the same name. It's when I try to use the native PHP function inside it. Then it uses MY function instead of the native one. That's because I'm inside the namespace.

Is there a way to call the trim function call inside the function without it using my namespace?

<?php
namespace Hello;

function trim($some, $arg) {
  return trim($some, $arg); // Calls Hello\trim() which is not what I want
}

Solution

  • \trim() calls trim function from global namespace:

    function trim($some, $arg) {
      return \trim($some, $arg);
    }