0

I have a class, that doesn't have a namespace.... I have another class that does have a name space... If I try to access the namespaced class from the non namespace, it can't find it. How do I tell my class to access the other class in the new namespace with PHP?

Thanks!

1 Answer 1

1

Precede the name of the namespace-less class with a \. For instance, to create a DateTime within a namespace, you could use:

<?php namespace bar;

class Foo {
  function hello() {
    echo new \DateTime();
  }
}

Conversely, you can access the namespaced class by preceding the class with the namespace and a \:

<?php
  $f = new \bar\Foo();
  $f->hello();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.