[PHP-DEV] Re: Syntactic improvement to array

2007-02-08 Thread Mathias Bank

Andi Gutmans schrieb:

Hi,

I thought I may have brought this up a long time ago but couldn't find anything 
in the archives.
For a long time already I've been thinking about possibly adding a new syntax 
for array(...) which would be shorter. I'd suggest
[...]. While I am usually not in favor of having more than one way to do 
things, I think it'd look much more elegant especially (but
not only) for nested arrays.

So what I'm thinking of is:
array(1, 2, 3) == [1, 2, 3]
array(1, 2, array(foo, bar)) == [1, 2, [foo, bar]]
array(key = 1, key2 = 2) == [key = 1, key2 = 2]

$arr = [1, 2, 3]
vs.
$arr = array(1, 2, 3)

Well enough examples given :)
I think it's not worth doing unless there's overwhelming support as it's not 
desperately needed. But I'd be interested to hear
people's thoughts. It seems implementation shouldn't be an issue but I'd have 
to dive a bit deeper.

Andi



Well, this discussion is really a stupid discussion. Obviously, there 
are some people, who likes this syntax ( in list() and array() form) but 
there are some people, who dislike it.


But I have to ask: what's the matter. A good programming language should 
not force the developer to program as the language wants. A good 
programming language should support the developer in writing code he 
likes, the way he likes.


Of course there could be problems with new developers. But the question 
is: is this relevant?
- Should php as programming language only provide one syntax only 
because new developers could have problems (or not, I don't think, that 
would be a great problem, because in other languages, this syntax is 
already usable).
- Should php only support one syntax so that every code is easier to 
maintain (if this is your only problem with foreign code, you are a 
really lucky guy!)


It don't think so: PHP is a good language, but writing code in PHP is 
sometimes awful. This could be improved by an alternative syntax. This 
could help new developers who are coming from another language. This 
could make coding funnier for some developers.


So: what's the matter? The idea of [] does not harm existent code. 
Everyone who does not like this syntax can avoid it in his code. But 
please don't tell others how they have to write their code! Let them write!


Mathias

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-08 Thread Hartmut Holzgraefe

Mathias Bank wrote:
It don't think so: PHP is a good language, but writing code in PHP is 
sometimes awful. This could be improved by an alternative syntax. This 
could help new developers who are coming from another language. This 
could make coding funnier for some developers.


Alternative syntax is what makes reading someone else's Perl code
funny ... ;(

 So: what's the matter? The idea of [] does not harm existent code.
 Everyone who does not like this syntax can avoid it in his code.
 But please don't tell others how they have to write their code!
 Let them write!

This violates a simple but important principle:

  The burden shall be on the writer, not the readers.

As long as you write code all by yourself and never share it in
any way your argument may hold true. The very second your code
needs to be read or even maintained by others alternative syntax
choices quickly become a nightmare. So you have to agree on one
form or the other and add yet another item to your coding style
rules list. So you even have to bother *more* about telling
others (or yourself) how to write code than you had to with only
one syntax alternative.

As a matter of taste i do prefer the [] alternative over the
current array()/list() approach. But we can't get rid of array()
or list() any time soon, even if we would decide to deprecate them
now in favor of []. So we're stuck with them and the nicer syntax
does not justify the can of worms opened by introducing an
alternative syntax for an already existing feature.

So if we were designing PHP today i'd be all for [] and [] only,
but as things are my vote is mostly against it even though i sort
of like the syntax.

So from my side a

  -0.8

--
Hartmut Holzgraefe, Senior Support Engineer.
MySQL AB, www.mysql.com

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-08 Thread Brian Moon
But I have to ask: what's the matter. A good programming language should 
not force the developer to program as the language wants. A good 
programming language should support the developer in writing code he 
likes, the way he likes.


So, you are new to php internal huh? =)

Seriously, the language can not be adapted to every whim of every 
developer.  Adding several ways to do things was fine when PHP was a 
neat tool to mess around with.  Now people's paychecks depend on it. 
IMO, it's a slippery slope to just add things because you can.



This could be improved by an alternative syntax.


Ah, but not all see it as an improvement.  Peronsally, every time I see 
this type of syntax in perl or javascript, I cringe.  Luckily I don't do 
much perl.  When I see it in JS, I change it.


The funny thing is that Andi probably could have just commited this to 
the PHP6 tree and made an announcement.  There would have been ~4 
replies and it would have been over with.


--

Brian Moon
-
http://dealnews.com/
It's good to be cheap =)

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-08 Thread Vlad Bosinceanu
I for one cringe when I see list(), and I'd love to see [$a, $b] = 
array(...) become an alternative to that. Can't say I care that much 
about an alternative syntax for dealing with array creation, but I 
wouldn't mind.


[] already suggests array, and I guess existing developers will have 
no problem picking it up. Newbies would bump into the docs just as they 
currently bump into the array section.


I don't see how an addition like this could affect people's paychecks.

V

Brian Moon wrote:
But I have to ask: what's the matter. A good programming language 
should not force the developer to program as the language wants. A 
good programming language should support the developer in writing 
code he likes, the way he likes.


So, you are new to php internal huh? =)

Seriously, the language can not be adapted to every whim of every 
developer.  Adding several ways to do things was fine when PHP was a 
neat tool to mess around with.  Now people's paychecks depend on it. 
IMO, it's a slippery slope to just add things because you can.



This could be improved by an alternative syntax.


Ah, but not all see it as an improvement.  Peronsally, every time I 
see this type of syntax in perl or javascript, I cringe.  Luckily I 
don't do much perl.  When I see it in JS, I change it.


The funny thing is that Andi probably could have just commited this to 
the PHP6 tree and made an announcement.  There would have been ~4 
replies and it would have been over with.




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] RE : [PHP-DEV] Re: Syntactic improvement to array

2007-02-06 Thread P
 From: Richard Lynch
 
 How many newbies will be trying:
 array[1, 2, 3];
 and left scratching their heads when it doesn't work?

Yes, even if I am in favor of the [] syntax, it is a good argument: 'array[ 1, 
2, 3]' can 
become a very common error, and not especially among newbies!

Maybe I am wrong, but would it be possible to accept all these syntaxes :

array(1, 2, 3)  (RHS only)
[ 1, 2, 3 ] (RHS=array / LHS=list, I especially like: '$x = [ $a, $b ] = 
f()' :)
list($a, $b)(LHS only)
array[1, 2, 3]  (RHS only)

For this purpose, we could say that the [] notation is optionally preceded by 
'array'.

Another idea if you want to make it easier to understand for newbies: make 
array() and list() 
synonyms, so that array() behaves as list() when LHS, and list() behaves as 
array() when RHS. 
IMHO, it would become simpler to explain.

If we implement both, we can even suppport 'list[ 1, 2, 3 ]'. How can we be 
more permissive?

Regards

Francois

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-06 Thread Andrei Zmievski
That's because you wouldn't be using those words with a newbie, if  
you are smart. You'd simply say it works like list() here and it  
works like array() here.


-Andrei


On Feb 5, 2007, at 3:41 PM, Richard Lynch wrote:


On Mon, February 5, 2007 12:06 pm, Andrei Zmievski wrote:

On Feb 4, 2007, at 8:52 PM, Richard Lynch wrote:


E!

So now we have an invisible operator with a magical symbol '[' which
*sometimes* means create an array, but *sometimes* means to
de-construct an array into individual variables?

That's just disgusting, imho.

-1 !!!


The way I view [] is that it creates an array context. When the
context is an RHS, it instantiates an array. When it's an LHS, the
context deconstructs the array.


I can 'splain list() to a newbie and get them to understand it as an
array deconstructor function thingie, and usually succeed in one or
two tries to get it into their heads.

I don't think I can do that with [] and LHS and RHS in anything like 2
tries...  More like 10 times, probably.

--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-06 Thread Andrei Zmievski

Now you're just grandstanding.

-Andrei


On Feb 5, 2007, at 3:55 PM, Richard Lynch wrote:


More edge cases:

$foo = array(1, 2, 3];
$bar = [1, 2, 3);

Syntax error because it's unbalancedO

Or kosher, because the choice of start/end delimiters should be up to
the user?

Should it match whatever rule is in place for:

if (...){
endif;



--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-06 Thread Richard Lynch
Actually, this one was prompted by seeing a bug fix or changelog about
requiring { } and : endif; to match up, rather than accepting
either/or in balance.

Synchronicity that I even saw that item, but there it is.

I would HOPE that they'd have to balance, but if they don't for the
long block syntax instead of braces, maybe they shouldn't.

Once you have two ways to delimit start and end, you ought to nail
down what does or doesn't work.

The Regex thing with  and  for start/end delimiters is also a
counter-example of what other people seem to like.

I prefer not to take things for granted when defining new syntax,
personally.

On Tue, February 6, 2007 11:28 am, Andrei Zmievski wrote:
 Now you're just grandstanding.

 -Andrei


 On Feb 5, 2007, at 3:55 PM, Richard Lynch wrote:

 More edge cases:

 $foo = array(1, 2, 3];
 $bar = [1, 2, 3);

 Syntax error because it's unbalancedO

 Or kosher, because the choice of start/end delimiters should be up
 to
 the user?

 Should it match whatever rule is in place for:

 if (...){
 endif;



 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some starving artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RE : [PHP-DEV] Re: Syntactic improvement to array

2007-02-06 Thread Richard Lynch
On Tue, February 6, 2007 8:17 am, LAUPRETRE François (P) wrote:
 From: Richard Lynch

 How many newbies will be trying:
 array[1, 2, 3];
 and left scratching their heads when it doesn't work?

 Yes, even if I am in favor of the [] syntax, it is a good argument:
 'array[ 1, 2, 3]' can
 become a very common error, and not especially among newbies!

 Maybe I am wrong, but would it be possible to accept all these
 syntaxes :

 array(1, 2, 3)  (RHS only)
 [ 1, 2, 3 ] (RHS=array / LHS=list, I especially like: '$x = [ $a,
 $b ] = f()' :)
 list($a, $b)(LHS only)
 array[1, 2, 3]  (RHS only)

 For this purpose, we could say that the [] notation is optionally
 preceded by 'array'.

 Another idea if you want to make it easier to understand for newbies:
 make array() and list()
 synonyms, so that array() behaves as list() when LHS, and list()
 behaves as array() when RHS.
 IMHO, it would become simpler to explain.

 If we implement both, we can even suppport 'list[ 1, 2, 3 ]'. How can
 we be more permissive?

I probably needn't even post this, but:

-1

Having even more ways to do everything is just confusing, not handy.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Christian Schneider

Richard Lynch wrote:

So now we have an invisible operator with a magical symbol '[' which
*sometimes* means create an array, but *sometimes* means to
de-construct an array into individual variables?


The distinction you are making is from an implementation point of view. 
From a language users point of view you're just dealing with arrays. 
Some people consider the distinction of the two a feature, some consider 
it a bug.



That's just disgusting, imho.


To me it makes array usage more orthogonal and hence simpler, but that's 
obviously a matter of taste.


What's also beautiful about [] IMHO is the symmetry of the syntax, 
list() and array() are asymmetrical which I always found inferior.



- func('foo' = $foo, 'bar' = $bar, ...)   equivalent to
func(array('foo' = $foo, 'bar' = $bar, ...), see
http://cschneid.com/php/ for more info


Again, saving 5 characters just to confuse the hell out of idiots like
me does not seem like a win for PHP. :-v


It is NOT about saving characters. If is about less clutter. The more 
important saving for us is the removal of an additional pair of parens 
which look like line-noise when nested. Funnily enough I forgot the 
closing parens of array() in my example above :-)


I agree that our function call syntax is somewhat magical as it 
automatically starts and stops the array-composition when encountering 
key = value pairs so I wasn't really expecting much love for this from 
the list. But one can dream :-)


Anyway, back to the main topic: I'm surprised how much hate a syntactic 
change like the one proposed by Andi still provokes nowadays when well 
established languages like C, C++, Javascript, Python and Ruby seem to 
successfully use [] or {} to construct arrays.


My personal summary of this thread is: We won't have syntactic sugar for 
common things like arrays, named parameter emulation and the like ever 
because it will be killed by the we already have a way of doing this 
and the you cannot look it up argument. Shame, that would be the tiny 
language development I'd personally benefit from.


Regards,
- Chris

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Lukas Kahwe Smith

Christian Schneider wrote:

My personal summary of this thread is: We won't have syntactic sugar for 
common things like arrays, named parameter emulation and the like ever 
because it will be killed by the we already have a way of doing this 
and the you cannot look it up argument. Shame, that would be the tiny 
language development I'd personally benefit from.


Named parameters is not just syntax sugar, as they would make it 
possible to get compiler errors and phpoc support automatically over 
having to implement some array based solution to trigger errors and some 
other formatting standard for phpdoc. Then again we had this discussion 
before as well, and unfortunately it was shot down (IIRC mainly because 
people to think that named parameters should then be implemented for all 
existing functions as well, which would be too much work .. then again 
unicode conversion might (have been) the perfect time to do this).


regards,
Lukas

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread P
 From: Christian Schneider [mailto:[EMAIL PROTECTED] 

 What's also beautiful about [] IMHO is the symmetry of the syntax, 
 list() and array() are asymmetrical which I always found inferior.

Agree. +1 for me, especially for this reason, even after reading Greg's 
examples :) IMO, it is 
more important to provide an elegant alternative to list() than a new syntax 
for array().

 
  - func('foo' = $foo, 'bar' = $bar, ...)   equivalent to
  func(array('foo' = $foo, 'bar' = $bar, ...)

Argh! Reading such a line, I think of named parameters, not an array. Ugly, 
confusing. -1 for 
me. Definitely.

May I add that, as I regularly write multi-layer arrays as SOAP return values, 
I personnaly 
like this proposed syntax.

Francois
 

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread ivailo91
That would be very handy. As I code frequently JavaScript and ActionScript, I 
will use this feature
with pleasure. +2 for me :D The array(), especially for more-than-1 dimensional 
arrays is very
cumbersome.

Best Regards,
Ivailo Karamanolev

On Monday, February 5, 2007, 12:53:44 PM, LAUPRETRE François[EMAIL PROTECTED] 
wrote:
 From: Christian Schneider [mailto:[EMAIL PROTECTED] 

 What's also beautiful about [] IMHO is the symmetry of the syntax, 
 list() and array() are asymmetrical which I always found inferior.

 Agree. +1 for me, especially for this reason, even after reading Greg's 
 examples :) IMO, it is
 more important to provide an elegant alternative to list() than a new syntax 
 for array().

 
  - func('foo' = $foo, 'bar' = $bar, ...)   equivalent to
  func(array('foo' = $foo, 'bar' = $bar, ...)

 Argh! Reading such a line, I think of named parameters, not an array. Ugly, 
 confusing. -1 for
 me. Definitely.

 May I add that, as I regularly write multi-layer arrays as SOAP return 
 values, I personnaly
 like this proposed syntax.

 Francois
  

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Richard Quadling

On 05/02/07, LAUPRETRE François (P) [EMAIL PROTECTED] wrote:

 From: Christian Schneider [mailto:[EMAIL PROTECTED]
  - func('foo' = $foo, 'bar' = $bar, ...)   equivalent to
  func(array('foo' = $foo, 'bar' = $bar, ...)

Argh! Reading such a line, I think of named parameters, not an array. Ugly, 
confusing. -1 for
me. Definitely.


I agree with Francois here. Other than looking STRONLY like named
parameters, surely there is a flaw if a declaration is ...

function convert(array $from, array $to)

If the calling code is ...

convert('foo' = $foo, 'bar' = $bar, ...)

where is the boundaries for the 2 arrays?

There would need to be SOMETHING.



convert('foo'


--
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
Standing on the shoulders of some very clever giants!


Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Andrei Zmievski

On Feb 4, 2007, at 8:52 PM, Richard Lynch wrote:


E!

So now we have an invisible operator with a magical symbol '[' which
*sometimes* means create an array, but *sometimes* means to
de-construct an array into individual variables?

That's just disgusting, imho.

-1 !!!


The way I view [] is that it creates an array context. When the 
context is an RHS, it instantiates an array. When it's an LHS, the 
context deconstructs the array.


-Andrei

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Stanislav Malyshev

So now we have an invisible operator with a magical symbol '[' which
*sometimes* means create an array, but *sometimes* means to
de-construct an array into individual variables?


Yep. We also have an invisible magical operator (), which sometimes 
means function definition, sometimes means expression grouping, 
sometimes means delimiter, sometimes means function call and sometimes 
means regular expression grouping. How do we manage? ;)


--
Stanislav Malyshev, Zend Products Engineer
[EMAIL PROTECTED]  http://www.zend.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Todd Ruth
Would this be legal?

function f() {
return [ 1, 2 ];
}

$x = [ $a, $b ] = f();

In the end, would we have...?
$a = 1;
$b = 2;
$x = array(1,2);

I'm not trying to be positive or negative about the
syntax.  I'm just testing somewhat edge cases.

- Todd

On Mon, 2007-02-05 at 10:06 -0800, Andrei Zmievski wrote:
...
 The way I view [] is that it creates an array context. When the 
 context is an RHS, it instantiates an array. When it's an LHS, the 
 context deconstructs the array.
 
 -Andrei
 

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Andrei Zmievski
Good question. If it's possible to make it behave this way, I don't see 
why not. On the other hand, if you take list(), it can't be used in 
RHS.


-Andrei

On Feb 5, 2007, at 10:28 AM, Todd Ruth wrote:


Would this be legal?

function f() {
return [ 1, 2 ];
}

$x = [ $a, $b ] = f();

In the end, would we have...?
$a = 1;
$b = 2;
$x = array(1,2);

I'm not trying to be positive or negative about the
syntax.  I'm just testing somewhat edge cases.

- Todd


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Richard Lynch
On Mon, February 5, 2007 12:06 pm, Andrei Zmievski wrote:
 On Feb 4, 2007, at 8:52 PM, Richard Lynch wrote:

 E!

 So now we have an invisible operator with a magical symbol '[' which
 *sometimes* means create an array, but *sometimes* means to
 de-construct an array into individual variables?

 That's just disgusting, imho.

 -1 !!!

 The way I view [] is that it creates an array context. When the
 context is an RHS, it instantiates an array. When it's an LHS, the
 context deconstructs the array.

I can 'splain list() to a newbie and get them to understand it as an
array deconstructor function thingie, and usually succeed in one or
two tries to get it into their heads.

I don't think I can do that with [] and LHS and RHS in anything like 2
tries...  More like 10 times, probably.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Richard Lynch




On Mon, February 5, 2007 12:05 pm, Stanislav Malyshev wrote:
 So now we have an invisible operator with a magical symbol '[' which
 *sometimes* means create an array, but *sometimes* means to
 de-construct an array into individual variables?

 Yep. We also have an invisible magical operator (), which sometimes
 means function definition, sometimes means expression grouping,
 sometimes means delimiter, sometimes means function call and sometimes
 means regular expression grouping. How do we manage? ;)

How you manage is that a zillion newbies use:

include(foo.inc);
echo(foo.inc);

and they don't even realize that the () doesn't mean what they think
it means, and it just works because it's a no-op.

*THAT* is harder to explain than just about anything in PHP syntax.

How many newbies will be trying:
array[1, 2, 3];
and left scratching their heads when it doesn't work?

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Richard Lynch
More edge cases:

$foo = array(1, 2, 3];
$bar = [1, 2, 3);

Syntax error because it's unbalancedO

Or kosher, because the choice of start/end delimiters should be up to
the user?

Should it match whatever rule is in place for:

if (...){
endif;



-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Mike Robinson
Richard Lynch wrote:
 More edge cases:
 
 $foo = array(1, 2, 3];
 $bar = [1, 2, 3);
 
 Syntax error because it's unbalancedO
 
 Or kosher, because the choice of start/end delimiters should 
 be up to the user?
 
 Should it match whatever rule is in place for:
 
 if (...){
 endif;


echo(foo.inc);
echo foo.inc;

$foo = array(1,2,3);
$foo = [1,2,3];

echo $foo[0];
echo $foo{0};

$foo = [1,2,3);  // parse error
echo(foo.inc;  // parse error


Come on. This isn't rocket science, even for newcomers.
It certainly isn't worthy of the [awesome] level of analysis it's getting.
Holy smokes.


Best,

Mike Robinson

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Robert Cummings
On Mon, 2007-02-05 at 17:46 -0600, Richard Lynch wrote:

 On Mon, February 5, 2007 12:05 pm, Stanislav Malyshev wrote:
  So now we have an invisible operator with a magical symbol '[' which
  *sometimes* means create an array, but *sometimes* means to
  de-construct an array into individual variables?
 
  Yep. We also have an invisible magical operator (), which sometimes
  means function definition, sometimes means expression grouping,
  sometimes means delimiter, sometimes means function call and sometimes
  means regular expression grouping. How do we manage? ;)
 
 How you manage is that a zillion newbies use:
 
 include(foo.inc);
 echo(foo.inc);
 
 and they don't even realize that the () doesn't mean what they think
 it means, and it just works because it's a no-op.

It's not a no-op, I'm sure it actually applies parenthesis precedence on
the expression foo.inc :) Personally, I use the parenthesis when using
include and require because I prefer it that way... though I don't doubt
some newbies think it's a function *heh*.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Sara Golemon
I would argue that list() (and [] when used like list()) should remain a 
terminal expression.  Yes it's possible to make it non-terminal, but I 
don't like what the resulting syntax winds up looking like.


-Sara

Good question. If it's possible to make it behave this way, I don't see 
why not. On the other hand, if you take list(), it can't be used in RHS.


-Andrei

On Feb 5, 2007, at 10:28 AM, Todd Ruth wrote:


Would this be legal?

function f() {
return [ 1, 2 ];
}

$x = [ $a, $b ] = f();

In the end, would we have...?
$a = 1;
$b = 2;
$x = array(1,2);

I'm not trying to be positive or negative about the
syntax.  I'm just testing somewhat edge cases.

- Todd


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-05 Thread Edin Kadribasic


On Feb 6, 2007, at 0:46, Richard Lynch wrote:

and they don't even realize that the () doesn't mean what they think
it means, and it just works because it's a no-op.


() is not a no-op.

return ($a) vs. return $a could cause PHP to corrupt memory and crash :)

Edin


--
Edin Kadribasic, Emini A/S
Symbion Science Park, Fruebjergvej 3
DK-2100 Copenhagen Ø, Denmark
Phone: +45 3917 8335
Mobile: +45 228 226 11
[EMAIL PROTECTED]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: Syntactic improvement to array

2007-02-04 Thread Christian Schneider

Andi Gutmans wrote:

So what I'm thinking of is:
array(1, 2, 3) == [1, 2, 3]


I like this syntax, more conscise but still clear (and well established 
in other languages by now).


Two more thoughts (but please don't kill Andi's proposal because of it, 
rather dismiss my comments instead ;-)):

- [$a, $b, $c] = ...equivalent tolist($a, $b, $c) = ...
- func('foo' = $foo, 'bar' = $bar, ...)   equivalent to 
func(array('foo' = $foo, 'bar' = $bar, ...), see 
http://cschneid.com/php/ for more info


Regards,
- Chris

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: Syntactic improvement to array

2007-02-04 Thread Sara Golemon

So what I'm thinking of is:
array(1, 2, 3) == [1, 2, 3]
array(1, 2, array(foo, bar)) == [1, 2, [foo, bar]]
array(key = 1, key2 = 2) == [key = 1, key2 = 2]


An enthusiastic thumbs-sideways.

I'll probably use this at some point, but not for anything which needs 
to be version agnostic.


-Sara

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Syntactic improvement to array

2007-02-04 Thread Richard Lynch
On Sun, February 4, 2007 8:23 am, Christian Schneider wrote:
 Andi Gutmans wrote:
 So what I'm thinking of is:
 array(1, 2, 3) == [1, 2, 3]

 I like this syntax, more conscise but still clear (and well
 established
 in other languages by now).

 Two more thoughts (but please don't kill Andi's proposal because of
 it,
 rather dismiss my comments instead ;-)):
 - [$a, $b, $c] = ...equivalent tolist($a, $b, $c) = ...

E!

So now we have an invisible operator with a magical symbol '[' which
*sometimes* means create an array, but *sometimes* means to
de-construct an array into individual variables?

That's just disgusting, imho.

-1 !!!

 - func('foo' = $foo, 'bar' = $bar, ...)   equivalent to
 func(array('foo' = $foo, 'bar' = $bar, ...), see
 http://cschneid.com/php/ for more info

Again, saving 5 characters just to confuse the hell out of idiots like
me does not seem like a win for PHP. :-v

-1

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: Syntactic improvement to array

2007-02-04 Thread Gregory Beaver
Andi Gutmans wrote:
 Hi,
 
 I thought I may have brought this up a long time ago but couldn't find 
 anything in the archives.
 For a long time already I've been thinking about possibly adding a new syntax 
 for array(...) which would be shorter. I'd suggest
 [...]. While I am usually not in favor of having more than one way to do 
 things, I think it'd look much more elegant especially (but
 not only) for nested arrays.
 
 So what I'm thinking of is:
 array(1, 2, 3) == [1, 2, 3]
 array(1, 2, array(foo, bar)) == [1, 2, [foo, bar]]
 array(key = 1, key2 = 2) == [key = 1, key2 = 2]
 
 $arr = [1, 2, 3]
 vs.
 $arr = array(1, 2, 3)
 
 Well enough examples given :)
 I think it's not worth doing unless there's overwhelming support as it's not 
 desperately needed. But I'd be interested to hear
 people's thoughts. It seems implementation shouldn't be an issue but I'd have 
 to dive a bit deeper.

future:
?php
$a = [1, 2, 3];
$a[1] = [1];
$a = [1];
[$a] = $a;
$a[] = [];
echo $a.[1]; // not a parse error
?

now:
?php
$a = array(1, 2, 3);
$a[1] = array(1);
$a = array(1);
list($a) = $a;
$a[] = array();
echo $a.[1]; // now a parse error
?

For what it's worth, the examples above show why I'm a strong -1 on this
idea.  It introduces the possibility of weird misunderstandings that
just don't exist now, and also introduces a new way to accidentally
break your script that wasn't possible before.

The only way I could see solving this would be:

1) [] != list()
2) use a[] as in $a = a[1, 2, 3] but then we might as well stick with
array().

Either way, [] is overloaded in the new definition:

1) array access
2) ArrayAccess object offsetGet/offsetSet
3) incremental index ($a[] = 1;)
4) array creation
[5) list()]

Whereas now, it is only 3 possible meanings, all of which are consistent
with a few quirks in the ArrayAccess one as of PHP 5.2.

Greg

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php