Hi!
Attached is the patch that implements multiple elements in use
statement, like this:
use foo::bar as baz, foo::baz as bazbaz;
Any objections to it?
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
Hi
Looks pretty good to me, I would prefer to have that insted of multiple use
statements after each other like you can do with the global keyword.
"+1" from me
Kalle
----- Original Message -----
From: "Stanislav Malyshev" stas@zend.com
To: "'PHP Internals'" internals@lists.php.net
Sent: Sunday, June 01, 2008 6:09 PM
Subject: [PHP-DEV] multiple use
Hi!
Attached is the patch that implements multiple elements in use
statement, like this:use foo::bar as baz, foo::baz as bazbaz;
Any objections to it?
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
Index: zend_language_parser.y
RCS file: /repository/ZendEngine2/zend_language_parser.y,v
retrieving revision 1.160.2.4.2.8.2.20
diff -u -r1.160.2.4.2.8.2.20 zend_language_parser.y
--- zend_language_parser.y 7 May 2008 12:04:37 -0000 1.160.2.4.2.8.2.20
+++ zend_language_parser.y 28 May 2008 19:12:45 -0000
@@ -172,13 +172,21 @@
| class_declaration_statement { zend_do_early_binding(TSRMLS_C); }
|T_HALT_COMPILER
'(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C);
YYACCEPT; }
|T_NAMESPACE
namespace_name ';' { zend_do_namespace(&$2 TSRMLS_CC); }
- |
T_USE
namespace_name ';' { zend_do_use(&$2, NULL, 0 TSRMLS_CC); }- |
T_USE
namespace_nameT_AS
T_STRING ';' { zend_do_use(&$2, &$4, 0
TSRMLS_CC); }- |
T_USE
T_PAAMAYIM_NEKUDOTAYIMT_STRING
';' { zend_do_use(&$3, NULL, 1
TSRMLS_CC); }- |
T_USE
T_PAAMAYIM_NEKUDOTAYIMT_STRING
T_AST_STRING
';' {
zend_do_use(&$3, &$5, 1 TSRMLS_CC); }
- |
T_USE
use_declarations ';'
| constant_declaration ';'
;+use_declarations:
- use_declarations ',' use_declaration
- | use_declaration
+use_declaration:
- namespace_name { zend_do_use(&$1, NULL, 0 TSRMLS_CC); }
- | namespace_name
T_AS
T_STRING { zend_do_use(&$1, &$3, 0 TSRMLS_CC); }- |
T_PAAMAYIM_NEKUDOTAYIM
T_STRING { zend_do_use(&$2, NULL, 1
TSRMLS_CC); }- |
T_PAAMAYIM_NEKUDOTAYIM
T_STRINGT_AS
T_STRING { zend_do_use(&$2, &$4,
1 TSRMLS_CC); }constant_declaration:
constant_declaration ','T_STRING
'=' static_scalar {
zend_do_declare_constant(&$3, &$5 TSRMLS_CC); }
|T_CONST
T_STRING '=' static_scalar { zend_do_declare_constant(&$2, &$4
TSRMLS_CC); }
Hi!
Attached is the patch that implements multiple elements in use statement,
like this:use foo::bar as baz, foo::baz as bazbaz;
Any objections to it?
Yes.
I find the whole namespace issue complicated enough as it is.
"importing" multiple namespaces and "aliasing" various
classess/functions all in one line decreases the readability imo.
-Hanens
Hi!
I find the whole namespace issue complicated enough as it is.
"importing" multiple namespaces and "aliasing" various
classess/functions all in one line decreases the readability imo.
I must say I fail to understand how it's decreasing readability. Is
function foo($a, $b, $c) hard to read? Is array(1, 2, 3) hard to read?
Is global $a, $b, $c hard to read? is implements Foo, Bar, Baz hard to
read? Is const $a = 1, $b = 2 hard to read? What exactly is hard in it?
Almost all structures in PHP that allow multiple elements allow
definitions chained with , - const, var, static, etc. What makes this
one so special that it becomes unreadable one it has comma in it?
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
Hi!
I find the whole namespace issue complicated enough as it is.
"importing" multiple namespaces and "aliasing" various
classess/functions all in one line decreases the readability imo.I must say I fail to understand how it's decreasing readability. Is function
foo($a, $b, $c) hard to read? Is array(1, 2, 3) hard to read? Is global $a,
$b, $c hard to read? is implements Foo, Bar, Baz hard to read? Is const $a =
1, $b = 2 hard to read? What exactly is hard in it?
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar, And::other:namespace
as foobar;
vs
use FooBar::In::Some::NameSpace as foo;
use SomeOther::Cool:Massive::awesome::space as bar;
use And::other:namespace as foobar;
Almost all structures in PHP that allow multiple elements allow definitions
chained with , - const, var, static, etc. What makes this one so special
that it becomes unreadable one it has comma in it?
You are comparing apples and oranges. Do we allow foreach($array as
$key => $arrayval as $key2 => $val) ?
-Hannes
Hi!
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar, And::other:namespace
as foobar;
vs
use FooBar::In::Some::NameSpace as foo;
use SomeOther::Cool:Massive::awesome::space as bar;
use And::other:namespace as foobar;
Well, with (im)proper formatting many things can be unreadable, but
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar,
And::other:namespace as foobar;
doesn't seem unreadable at all to me. Repeating "use" is just clutter
which doesn't add anything. And btw not all names are that long - when I
actually used namespaces in the code, I found that it'd be much easier
if I could chain declarations. Just as it is easier to do $a =
array(1,2,3) and not $a = array(); $a[0] = 1; $a[1] = 2; $a[2] = 3;
You are comparing apples and oranges. Do we allow foreach($array as
$key => $arrayval as $key2 => $val) ?
What foreach has to do with it? Foreach doesn't allow multiple elements
at all. But definitions that do - like const, static, var, etc. - allow
commas.
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
Hi!
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar, And::other:namespace
as foobar;
vs
use FooBar::In::Some::NameSpace as foo;
use SomeOther::Cool:Massive::awesome::space as bar;
use And::other:namespace as foobar;Well, with (im)proper formatting many things can be unreadable, but
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar,
And::other:namespace as foobar;doesn't seem unreadable at all to me. Repeating "use" is just clutter which
doesn't add anything. And btw not all names are that long - when I actually
used namespaces in the code, I found that it'd be much easier if I could
chain declarations. Just as it is easier to do $a = array(1,2,3) and not $a
= array(); $a[0] = 1; $a[1] = 2; $a[2] = 3;
I don't know what else I can say. You asked if someone had objections
and I replied stating my personal opinion that I find explicit use
statements in multiple lines more readable.
I don't really see the point in dropping three characters if you are
going to indent it just the same anyway, doesn't even safe you a
single keystroke..
-Hannes
Hannes Magnusson wrote:
Hi!
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar, And::other:namespace
as foobar;
vs
use FooBar::In::Some::NameSpace as foo;
use SomeOther::Cool:Massive::awesome::space as bar;
use And::other:namespace as foobar;
Well, with (im)proper formatting many things can be unreadable, but
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar,
And::other:namespace as foobar;doesn't seem unreadable at all to me. Repeating "use" is just clutter which
doesn't add anything. And btw not all names are that long - when I actually
used namespaces in the code, I found that it'd be much easier if I could
chain declarations. Just as it is easier to do $a = array(1,2,3) and not $a
= array(); $a[0] = 1; $a[1] = 2; $a[2] = 3;I don't know what else I can say. You asked if someone had objections
and I replied stating my personal opinion that I find explicit use
statements in multiple lines more readable.
Perhaps it is. But like mentioned earlier, you can do it with multiple
things already, it only makes sense adding that support to the use
feature also.
I don't really see the point in dropping three characters if you are
going to indent it just the same anyway, doesn't even safe you a
single keystroke..
I'd say use <tab> more often :->
You don't have to use it, it doesn't exclude the other.
-Hannes
If it's not too much work, and if it doesn't break anything.
I'd say just add it, let's not counter every patch that makes it to the
list.
- Mark
On Sunday 01 June 2008 23:32:58 Hannes Magnusson wrote:
I don't know what else I can say. You asked if someone had objections
and I replied stating my personal opinion that I find explicit use
statements in multiple lines more readable.
I don't really see the point in dropping three characters if you are
going to indent it just the same anyway, doesn't even safe you a
single keystroke..-Hannes
It seems to me you should seek out a proper editor :) It could (and should) do
such indentation things for you automatically.
Regards,
Stefan
Hi!
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar, And::other:namespace
as foobar;
vs
use FooBar::In::Some::NameSpace as foo;
use SomeOther::Cool:Massive::awesome::space as bar;
use And::other:namespace as foobar;Well, with (im)proper formatting many things can be unreadable, but
use FooBar::In::Some::NameSpace as foo,
SomeOther::Cool:Massive::awesome::space as bar,
And::other:namespace as foobar;doesn't seem unreadable at all to me. Repeating "use" is just clutter which
doesn't add anything. And btw not all names are that long - when I actually
used namespaces in the code, I found that it'd be much easier if I could
chain declarations. Just as it is easier to do $a = array(1,2,3) and not $a
= array(); $a[0] = 1; $a[1] = 2; $a[2] = 3;I don't know what else I can say. You asked if someone had objections
and I replied stating my personal opinion that I find explicit use
statements in multiple lines more readable.
I don't really see the point in dropping three characters if you are
going to indent it just the same anyway, doesn't even safe you a
single keystroke..
I've to agree with this.
Derick
--
Derick Rethans
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org
Hi!
It's not dropping three characters, it's making better user experience.
I see lately on the list very strange total opposition to any feature
that adds any usability or syntax sugar to PHP. Like features supported
by a bunch of community people but opposed by some core developers on
abstract reasons of "it's unreadable" or "I don't like it".
I wonder why is that? What's wrong with being nicer to the user? Is
usability a taboo in PHP now?
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
hi,
Hi!
I wonder why is that?
Conservatism (and we are all conservative depending on what you ask...sadly)
What's wrong with being nicer to the user?
nothing
Is usability a taboo in PHP now?
no
+1 for this feature. If one does not like it, he can always ignore it
and add a note in his coding standard.
Cheers,
From: Stanislav Malyshev wrote:
Hi!Attached is the patch that implements multiple elements in use
statement, like this:use foo::bar as baz, foo::baz as bazbaz;
Any objections to it?
A very nice addition. I have use for this.
Two thumbs up. :)
Best Regards
Mike Robinson