Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does backslash do as prefix to a function name? [duplicate]

Tags:

php

Preparing for the ZEND-Exam, I found a question where a class redefined the strlen-function:

namespace MyFramework\MyString
{
  function strlen ($str) 
  {
    return \strlen($str) * 2; // return double string-length
  }

}

I never came across that "\function"-thing before and could not get an explanation from my trainer - can somebody pls. help shed some light...?

like image 269
MBaas Avatar asked Jul 11 '13 13:07

MBaas


1 Answers

It calls a function from the global namespace.

You need it only if there's a function of the same name in the current namespace.

like image 85
holographic-principle Avatar answered Oct 30 '22 19:10

holographic-principle