Jens Törnell
Jens Törnell

Reputation: 24748

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
}

Upvotes: 1

Views: 89

Answers (2)

Ali Faris
Ali Faris

Reputation: 18592

checkout the docs

use \trim() to call the global function

Upvotes: 0

u_mulder
u_mulder

Reputation: 54831

\trim() calls trim function from global namespace:

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

Upvotes: 3

Related Questions