Re: namespaces?
| From: | Andi Gutmans | Date: | Fri, 13 Jul 2001 07:04:01 +0000 |
| Subject: | Re: namespaces? | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-702@lists.php.net to get a copy of this message | ||
At 08:09 PM 7/12/2001 -0400, Jeff Stuart wrote:
As an FYI, I think that if PHP followed perl's guidance here for classes/name spaces, it might work out well. Perl has 2 constructs for this. 1) Use:This is exactly what I was saying. A namespace will have to be file scoped because of the nature of PHP & Perl. If this is acceptable by people then there is good grounds for a solution.This construct is used by the programs that want to USE a specific class. In the process of the use statement, a name space for the package is setup. This is defined by #2. Use statements look something like this:use CGI::FastTemplate;What this does is it goes out and finds the file CGI/FastTemplate.pm and includes the contents of the file (ala the include/require statement in PHP) into the current source code.2) Package:This construct is used inside each class definition and defines the actual namespace for the class (class and package in perl are used interchangably as perl created classes out of it's package mechanism.). IE In the FastTemplate file, the first line would be:Package CGI::FastTemplate; This line is what actually defines the name space. From now on, ALL variables inside this file (FYI, name spaces are file scoped) will implicitly be in the CGI::FastTemplate name space. IE the FULL name of the variable $loop would REALLY be $CGI::FastTemplate::loop. And if I wanted to refer to this variable OUTSIDE of the class, I would have to use that syntax.
Now perl isn't truely OOP. IE you can't have private/protected members ase you can in C++ and company. But for the most part, this works quite well! :)Well we won't be using namespaces to reimplement our classes like Perl. I consider PHP ten-folds better than Perl when it comes to clarity and the existing PHP classes are a good example of that. Of course, IMO they need the new face lift but that is more an internal face lift and not syntax. Andi