Re: YANP (Yet Another Namespace Proposal)
| From: | Jessie Hernandez | Date: | Thu, 07 Jul 2005 19:24:47 +0000 |
| Subject: | Re: YANP (Yet Another Namespace Proposal) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-17168@lists.php.net to get a copy of this message | ||
Could you elaborate on this? Let's say we have the following situation:
- a.php does a full namespace import of "my_namespace".
- The <class_path>/my_namespace directory has two files (classes),
class1.php and class2.php.
- a.php has the following code:
<?php
import namespace my_namespace;
$c1 = new class1();
$c2 = new class2();
?>
- After a.php is first run, a new file, class3.php, is added.
With the above scenario, nothing will be affected if there is an opcode
cache or not. The only situation I can think of where an opcode cache can
affect this is when the script DYNAMICALLY creates classes from the imported
namespace. Maybe there's other situations, but I can't come up with any at
the moment.
Either way, I'm not sure if full namespace imports are a good idea anyways.
Issues like the one you presented are one reason, and the other is that it
is bad practice. If multiple namespaces are imported, readability is
affected (which class belongs to which namespace?). Also, if two namespaces
are imported, and one day a new class is added to one which has the same
name as another, then there will suddenly be a compile error, and the error
will be elusive.
--
Jessie
"Stanislav Malyshev" <stas@zend.com> wrote in message
news:Pine.LNX.4.62.0507072119540.24702@mail.zend.com...
> JH>>// 1) "my_namespace:class1" is added to the import hashtable.
> JH>>// 2) The opcode for
> JH>>"require_once('/usr/local/php-classes/my_namespace/class1.php')"
> JH>>is
> JH>>generated.
> JH>>// 3) "my_namespace:class2" is added to the import hashtable.
> JH>>// 4) The opcode for
> JH>>"require_once('/usr/local/php-classes/my_namespace/class2.php')"
> JH>>is
> JH>>generated.
> JH>>?>
>
> This means, of course, that such file could not be used with bytecode
> caches, because between runs contents of the directory can change.
>
> --
> Stanislav Malyshev, Zend Products Engineer
> stas@zend.com http://www.zend.com/ +972-3-6139665 ext.115