SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Quick Namespace Question

    Is it possible to create objects in one namespace from another?

    For example, if I am in the global namespace and I want to create an object in the config namespace, can I do it, and if so how?

    The obvious appears to be something like this to me:

    Code PHP:
    namespace {
        config\$object = new config\class();
    }

    This isn't working for me however. Am I doing something wrong or is it just not possible?

    I get this error:

    Parse error: parse error, expecting `T_STRING' in...

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Code php:
    $config = new \config\namespace\class();
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Won't that create the object in the current namespace? I'm wanting to create an object in a different namespace to the one I'm in, if possible.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    variables do not exists in any namespace but the global namespace.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ah, then that is the simple answer I was looking for. Cheers


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •