tomew
tomew

Reputation: 57

Using Namespaces but not for default classes

Since yesterday I am going to use namespaces in php and I have a little problem there:

namespace NamespaceName;

use StdClass;

$s = new StdClass;
$s->meow = "Hello World";

echo $s->meow;

Is there any way that I must not include the "use StdClass"?

Upvotes: 1

Views: 35

Answers (1)

Rizier123
Rizier123

Reputation: 59681

You just have to put a backspace in your declaration, so that you use StdClass from the global namespace:

 $s = new \StdClass;
        //^ See here

Upvotes: 1

Related Questions