rfc:namespaces
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:namespaces [2008/09/15 12:10] – visual tweak jochem | rfc:namespaces [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 41: | Line 41: | ||
- 5. Importing NameSpace:: | - 5. Importing NameSpace:: | ||
- 6. **Static methods v. namespaced function ambiguities** | - 6. **Static methods v. namespaced function ambiguities** | ||
- | - 7. **Class constants v. constants ambiguities** | + | - 7. **Class constants v. namespaced |
- 8. use and includes | - 8. use and includes | ||
- 9. **Importing functions** | - 9. **Importing functions** | ||
Line 108: | Line 108: | ||
< | < | ||
defined(' | defined(' | ||
- | defined(' | + | defined(' |
defined(' | defined(' | ||
defined(' | defined(' | ||
Line 223: | Line 223: | ||
+ | ---- | ||
==== 3. Autoload & functions ==== | ==== 3. Autoload & functions ==== | ||
Line 329: | Line 330: | ||
+ | ---- | ||
==== 4. You can ' | ==== 4. You can ' | ||
Line 390: | Line 392: | ||
+ | ---- | ||
==== 5. Importing NameSpace:: | ==== 5. Importing NameSpace:: | ||
Line 444: | Line 447: | ||
+ | ---- | ||
==== 6. Static methods/ | ==== 6. Static methods/ | ||
+ | There is an abiguity, from the users point of view between static class method calls and namespaced function calls, essentially it is very difficult to determine (if at all) from the code, even given context, whether **TEST:: | ||
+ | class.inc: | ||
+ | <code php> | ||
+ | <?php | ||
+ | class TEST { | ||
+ | static function what() | ||
+ | static function where() { echo __FUNCTION__," | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | ns.inc: | ||
+ | <code php> | ||
+ | <?php | ||
+ | namespace TEST; | ||
+ | function what() { echo __FUNCTION__," | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | example1.php: | ||
+ | <code php> | ||
+ | <?php | ||
+ | include ' | ||
+ | include ' | ||
+ | TEST:: | ||
+ | TEST:: | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | output of example1.php (regardless of include order): | ||
+ | < | ||
+ | TEST::what in namespace | ||
+ | where in class | ||
+ | </ | ||
+ | |||
+ | There is no way to reference the static method **TEST:: | ||
+ | |||
+ | //There is a need to disambiguate these two calls, and to be able to call both regardless of the existence of the other.// | ||
+ | |||
+ | ---- | ||
==== 7. Class constants v. constants ambiguities ==== | ==== 7. Class constants v. constants ambiguities ==== | ||
+ | The same ambiguity that exists between static methods and namespaced functions also exists between class constants and namespaced constants. | ||
+ | From the users point of view it not possible to determine, with any easy or certainty, from the code whether **TEST:: | ||
+ | class.inc: | ||
+ | <code php> | ||
+ | <?php | ||
+ | class TEST { | ||
+ | const MY_CNST_ONE = 'TEST class CONSTANT ONE'; | ||
+ | const MY_CNST_TWO = 'TEST class CONSTANT TWO'; | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | ns.inc: | ||
+ | <code php> | ||
+ | <?php | ||
+ | namespace TEST; | ||
+ | const MY_CNST_ONE = 'TEST class CONSTANT ONE'; | ||
+ | ?> | ||
+ | |||
+ | example1.php: | ||
+ | <code php> | ||
+ | <?php | ||
+ | include ' | ||
+ | include ' | ||
+ | echo TEST:: | ||
+ | echo TEST:: | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | output of example1.php (regardless of include order): | ||
+ | < | ||
+ | TEST namespace CONSTANT ONE | ||
+ | TEST class CONSTANT TWO | ||
+ | </ | ||
+ | |||
+ | There is no way to reference the constant **MY_CNST_ONE** from class **TEST**, additionally because constant **MY_CNST_TWO** from class **TEST** is reachable one is left with the potential that the namespaced include will break current code if a constant **MY_CNST_TWO** is later defined in the TEST namespace, regardless it introduces confusion because one is it possible to retrieve constants from two different ' | ||
+ | |||
+ | //There is a need to disambiguate the constants, and to be able to reference both regardless of the existence of the other.// | ||
+ | |||
+ | |||
+ | ---- | ||
==== 8. **use** and includes ==== | ==== 8. **use** and includes ==== | ||
Line 469: | Line 552: | ||
+ | |||
+ | ---- | ||
==== 9. Importing functions ==== | ==== 9. Importing functions ==== | ||
Line 517: | Line 602: | ||
</ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
==== 10. Name resolution order ==== | ==== 10. Name resolution order ==== | ||
+ | |||
+ | ---- | ||
==== 11. Keywords in namespace names ==== | ==== 11. Keywords in namespace names ==== | ||
Line 589: | Line 679: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ---- | ||
==== 12. Namespace must be first declaration in file ==== | ==== 12. Namespace must be first declaration in file ==== | ||
Line 637: | Line 731: | ||
</ | </ | ||
- | ==== 12. Namespaces aren't implemented like in ... ==== | + | |
+ | |||
+ | ---- | ||
+ | |||
+ | ==== 13. Namespaces aren't implemented like in ... ==== | ||
PHP is not <insert your favorite language here>. Granted this is not an issue, but some of you reading this probably need something to smile about after reading the items above! | PHP is not <insert your favorite language here>. Granted this is not an issue, but some of you reading this probably need something to smile about after reading the items above! | ||
Line 660: | Line 758: | ||
> | > | ||
> If a fully qualified name is prefixed with function:: or const:: it will only check the namespace function/ | > If a fully qualified name is prefixed with function:: or const:: it will only check the namespace function/ | ||
- | + | > | |
- | ns_071.inc: | + | > ns_071.inc: |
- | <code php> | + | > <code php> |
<?php | <?php | ||
namespace foo; | namespace foo; | ||
Line 675: | Line 773: | ||
?> | ?> | ||
</ | </ | ||
- | ns_071.phpt: | + | > ns_071.phpt: |
- | <code php> | + | > <code php> |
--TEST-- | --TEST-- | ||
071: name conflict, function/ | 071: name conflict, function/ | ||
Line 717: | Line 815: | ||
This patch addresses the inability to include [html] output prior to the first **<? | This patch addresses the inability to include [html] output prior to the first **<? | ||
+ | To quote the author from his original post regarding this patch: | ||
+ | > This is a simple patch that allows files like this to work without parse error.: | ||
+ | > | ||
+ | > main.php: | ||
+ | > <code php> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | <?php | ||
+ | namespace my:: | ||
+ | |||
+ | // stuff | ||
+ | |||
+ | ?> | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
===== Miscellaneous ===== | ===== Miscellaneous ===== | ||
Line 759: | Line 876: | ||
* [[php-internals@119874502923978|Suggestion: | * [[php-internals@119874502923978|Suggestion: | ||
- | Nothing has been filtered on the basis of relevance! | + | //Nothing has been filtered on the basis of relevance |
Line 767: | Line 884: | ||
the articles & blog posts listed here are (hopefully) in reverse chronological order, please note that older items may no longer be relevant as the implementation has changed since the time the item was published: | the articles & blog posts listed here are (hopefully) in reverse chronological order, please note that older items may no longer be relevant as the implementation has changed since the time the item was published: | ||
+ | - [[http:// | ||
- [[http:// | - [[http:// | ||
- [[http:// | - [[http:// |
rfc/namespaces.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1