White Lotus
White Lotus

Reputation: 363

Calling a Method not Associated with a class inside class a PHP

I'm trying to use the PHP method time() within a class. I'm a little lost on how to call it since PHP thinks the time method is part of the class it's in.

Code

Class FingerPrint
{
     protected $time;

     public function __construct()
     {
          $this->time = time();
     }
}

Upvotes: 0

Views: 50

Answers (1)

cske
cske

Reputation: 2243

You have to prefix global function call with \

\time()

http://php.net/manual/en/language.namespaces.global.php

Without any namespace definition, all class and function definitions are placed into the global space - as it was in PHP before namespaces were supported. Prefixing a name with \ will specify that the name is required from the global space even in the context of the namespace.

Upvotes: 4

Related Questions