#1
  1. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,118
    Rep Power
    537

    Using namespace in one file


    I have two classes, foo and bar. I wish foo to be in the global namespace, yet bar to be only in the foo namespace. Maybe something like the following.

    Is it possible to do something like this when using only a single file?

    Thanks

    PHP Code:
    class foo{
      
    $f=new \foo\bar();
      
    $f->oof();

    PHP Code:
    namespace foo;

    class 
    bar {
      public function 
    oof() {
        ...
      }

  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,026
    Rep Power
    4101
    You can use brackets to control what is affected by a namespace. So you could do:
    Code:
    namespace foo {
        class bar {
        }
    }
    
    namespace {  //Root namespace
        class foo {
        }
    }

    Comments on this post

    • NotionCommotion agrees
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,118
    Rep Power
    537
    Originally Posted by kicken
    You can use brackets to control what is affected by a namespace. So you could do:
    Code:
    namespace foo {
        class bar {
        }
    }
    
    namespace {  //Root namespace
        class foo {
        }
    }
    Perfect!

IMN logo majestic logo threadwatch logo seochat tools logo