note 92423 added to language.namespaces.importing
| From: | rasmus at mindplay dot dk | Date: | Thu, 23 Jul 2009 17:44:05 +0000 |
| Subject: | note 92423 added to language.namespaces.importing | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158653@lists.php.net to get a copy of this message | ||
This is just not very useful.
What would be useful, is if "use" worked as a block statement, allowing you to switch the
execution context of a block to another scope, for example:
file1.php:
<?php
namespace Helpers;
function h1($str) {
echo "<h1>$str</h1>";
}
?>
file2.php:
<?php
require 'file1.php';
use Helpers {
echo
"<html><body>".h1('Hello')."</body></html>";
}
?>
Without the ability to actually switch the default namespace execution context, it's just not
much use at all - you will end up with the same amount of code you had before namespaces were
introduced, you will just have backslashes separating your function/class-names instead of
underscores.
We already had a way of "namespacing" apps in this way, so this feature doesn't
really help at all. Most people use one class per file, so you will still have to specify the
namespace in every file, same way you did when you prefixed the names.
I hope to see this function turn into something useful in the future...
----
Server IP: 209.41.74.194
Probable Submitter: 64.57.178.15
----
Manual Page -- http://www.php.net/manual/en/language.namespaces.importing.php
Edit -- https://master.php.net/note/edit/92423
Del: integrated -- https://master.php.net/note/delete/92423/integrated
Del: useless -- https://master.php.net/note/delete/92423/useless
Del: bad code -- https://master.php.net/note/delete/92423/bad+code
Del: spam -- https://master.php.net/note/delete/92423/spam
Del: non-english -- https://master.php.net/note/delete/92423/non-english
Del: in docs -- https://master.php.net/note/delete/92423/in+docs
Del: other reasons-- https://master.php.net/note/delete/92423
Reject -- https://master.php.net/note/reject/92423
Search -- https://master.php.net/manage/user-notes.php