Re: Re: PEAR2 Coding standards, Autoloading and Namespaces
| From: | Jeff Moore | Date: | Wed, 02 Apr 2008 06:56:17 +0000 |
| Subject: | Re: Re: PEAR2 Coding standards, Autoloading and Namespaces | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-49602@lists.php.net to get a copy of this message | ||
On Mar 29, 2008, at 3:13 PM, Greg Beaver wrote:
Jeff Moore wrote:Actually, I meant what I wrote. The question I was asking was about the relationship between the namespace and the package name, not necessarily the class. Thats why I think both the namespaces PEAR2::HTTP and PEAR2::HTTP::Request are confusing in this regard, but PEAR2::HTTP_Request is not.Should the recommended location of PEAR2::HTTP::Request somehow align the namespaces with package names? For example: namespace PEAR2::HTTP_Request; class Request {} or namespace PEAR2::HTTP::Request; class Request {}Actually, I believe what is intended is this code: <?php namespace PEAR2::HTTP; class Request {} ?> which would create the PEAR2::HTTP::Request class. The goal was to simply take what would have been a PEAR class and put PEAR2:: in front of it and s/_/::/
Can you suggest a revision to the docs that reflects this? Also, to be clear, existing coding standards require 2 segments like Foo_Bar (MDB2 was grandfathered in), this would then become a minimum of PEAR2::Foo::Bar, but this is an implicit assumption, I don't believe the new standards say anything in this regard either.I've played around with 5.3, namespaces and autoloading a small bit. I'm not yet sure the best practice here. For PEAR, the two level approach would appear to make sense where PEAR2::HTTP_Request can be mapped in an error message to a nice message telling you to "install the HTTP_Request package from PEAR" if a class cannot be located. The drawback to this is that the fully qualified class name for Request in this case is PEAR2::HTTP_Request::Request. More controversial would probably be the question of where the PEAR2 exception class would go? PEAR2::Exception::Exception? Since the goal of namespaces is to avoid naming collisions, not to place class files in specific folders (we have _ for that), I'm of the mind that going beyond two segments in a namespace. PEAR2::HTTP::Request is probably overkill. Since the goal of namespaces is to avoid naming collisions, I also think that each package should have one, since that seems to be the fundamental subdivision in PEAR. AFAIK there is no HTTP maintainer, so I am not sure that PEAR2::HTTP makes sense as a namespace for the HTTP_Request package. (Well, there is an HTTP package, but it looks like that may be a bit of legacy and does not have maintenance oversight over all the over all HTTP_ packages. Educate me if I am wrong.) So, I think I favor the two level namespace with PEAR2::Package_Name style. I've been converting some code to this style. I can write this up in a more formal way as I gain more insight from that. Jeff