About Namespace...Are you using it?

Anyone know or predict whether PHP will make any amendments to the namespace policy??

Basically when I try to incorporate namespace feature to my code, it creates a hell lots of inconvenience in terms of more typing and uses of \ in every part of the code really looks ugly!

I have in a class which uses many different exception classes like so:

use System|Exceptions as E;

class Simple{

     function a() {
         try{
         }
         catch( E|FileErrorException $e ) ...
         }
    }

    function b() {
         try{
         }
         catch( E|AnotherErrorException $e ) ...
         }
    }
}

Seriously this looks really ugly isn’t it??? Or am I the only one not getting used to it? :frowning:

(Note: I have to use | instead of \ as sitepoint removes it)

See…I just encounter another stupid cases:


use System|Http as Http;

class Request {

    protected static $request;
    protected static $response;

    function __construct( ) {
        self::$resquest = Http|HttpRequest( );
        self::$response = Http|HttpResponse( );
    }

    public static function getRequest() {
        return self::$request( );
    }

    public static function getResponse() {
        return self::$response( );
    }
}


// in file.php

class File extends Request { // is an extend

    function __construct( )
   {
          var_dump( Request::getRequest() ); // Error Not found so I have to "use"
          var_dump( Request::getResponse() ); // Error Not found so I have to "use"
   }
}

// Which means I have to input 2 use cases just for the above

use System|Http|HttpRequest;
use System|Http|HttpResponse;

// Because I can't do it this way...

use System|Http as Http;

Http|Request::getRequest();   <--- Is invalid

WTF! :frowning:
This is getting serious as the more I use it, the more I get confused with everywhere having the backslash. What if a new developer came in?? That would be a nightmare for him…even if folders are properly structured.

I agree that PHP’s implementation of namespaces is strange. Perhaps that is why fewer developers have started to use them? I think that most developers will begin to utilise namespaces when they are the foundation for key PHP frameworks, like Zend or CakePHP. Otherwise, there is little incentive considering the bizarre syntax.

However, I think that namespaces can be introduced properly to beginning developers such that they are not confusing. Python has ingrained namespaces that are easy to understand because they are presented from the very start of learning Python. With PHP, it seems like an afterthought and not a core principle.