Re: YANP (Yet Another Namespace Proposal)
| From: | Jessie Hernandez | Date: | Thu, 07 Jul 2005 14:58:09 +0000 |
| Subject: | Re: YANP (Yet Another Namespace Proposal) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-17166@lists.php.net to get a copy of this message | ||
I'm still debating whether importing all symbols from a namespace is a good
idea or not (I sometimes use Java at work, and I never import a full package
myself, and this is not recommended anyways). But, if it were to be
implemented, then below is how I would approach it. The following would be
required:
1) As I said before, the "class_path" php.ini variable would be used for
imports.
2) Each file under the class_path is named exactly like the class that it
declares. For example, my_namespace/my_class.php would define the class
"my_class" under the my_namespace namespace (just like in Java).
If an "import namespace my_namespace;" (the syntax is still tentative)
statement is found, then the directory <class-path>/my_namespace will be
opened (at compile-time). Each file under this directory would be imported.
So, assuming our class_path is "/usr/local/php-classes" and the
"/usr/local/php-classes/my_namespace" directory had two files, "class1.php"
and "class2.php", then this is what would happen:
<?php
import namespace my_namespace;
// Directory "/usr/local/php-classes/my_namespace" is opened.
// There are two files, class1.php and class2.php.
//
// 1) "my_namespace:class1" is added to the import hashtable.
// 2) The opcode for
"require_once('/usr/local/php-classes/my_namespace/class1.php')" is
generated.
// 3) "my_namespace:class2" is added to the import hashtable.
// 4) The opcode for
"require_once('/usr/local/php-classes/my_namespace/class2.php')" is
generated.
?>
There would also need to be another hashtable to indicate if a full
namespace import for a particular namespace has already been done or not, to
avoid a directory from being read over and over again.
--
Jessie
"Xuefer" <xuefer@gmail.com> wrote in message
news:28139bc05070705364cc572f7@mail.gmail.com...
at compile time? this means u cannot import * (all) symbols from a namespace