# [RFC]Call for voting about const array/string dereference

- Thread: https://externals.io/message/56901
- Original archive: https://news-web.php.net/php.internals/56901
- Started by Laruence on 2011-12-13T06:16:32+00:00
- Messages: 19
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #56901 — Laruence — 2011-12-13T06:16:32+00:00

URL: https://externals.io/message/56901#56901

Hi:
    Call for voting about the const array/string derefernce RFC now.

    you can find more info here: https://wiki.php.net/rfc/constdereference#vote


thanks

-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #56902 — Nikita Popov — 2011-12-13T06:20:38+00:00

URL: https://externals.io/message/56901#56902 · In reply to: #56901

This can't go into PHP 5.4.0 in any case, because it is a feature
addition and the release is already in RC.

Nikita


> Hi:
>    Call for voting about the const array/string derefernce RFC now.
>
>    you can find more info here: https://wiki.php.net/rfc/constdereference#vote
>
>
> thanks
>
> --
> Laruence  Xinchen Hui
> http://www.laruence.com/

---

## #56903 — Morfi — 2011-12-13T08:32:43+00:00

URL: https://externals.io/message/56901#56903 · In reply to: #56902

>
> echo "foobar"["foo"][0];


"foobar"["foo"] - Why not "undefined index"?

On Tue, Dec 13, 2011 at 10:20 AM, Nikita Popov <nikita.ppv@googlemail.com>wrote:

> This can't go into PHP 5.4.0 in any case, because it is a feature
> addition and the release is already in RC.
>
> Nikita
>
> 
> > […]
> https://wiki.php.net/rfc/constdereference#vote
> > […]

---

## #56904 — Ivan Enderlin @ Hoa — 2011-12-13T09:27:59+00:00

URL: https://externals.io/message/56901#56904 · In reply to: #56903

Hi all,


> > […]
>
>
> "foobar"["foo"] - Why not "undefined index"?
Exactly. The index/key "foo" does not really exist in the string 
"foobar" because a string is more an indexed array of characters than a 
combination of substrings (as the key "foo" could suggest).
"foobar"[3] has a well-defined meaning, but "foobar"["foo"] sounds 
strange for me :-). Which semantics do you attached to this syntax?

Cheers.
-- 
Ivan Enderlin
Developer of Hoa
http://hoa.42/ or http://hoa-project.net/

PhD. student at LIFC/DISC (Vesontio) and INRIA (Cassis)
http://lifc.univ-fcomte.fr/ and http://www.inria.fr/

Member of HTML and WebApps Working Group of W3C
http://w3.org/

---

## #56905 — Laruence — 2011-12-13T09:40:25+00:00

URL: https://externals.io/message/56901#56905 · In reply to: #56903

Hi:
   should consistent with :
<?php
   $a =  "string";
   echo $a["foo"][0];


   in 5.4.

thanks


> > […]
>
>
> "foobar"["foo"] - Why not "undefined index"?
>
> On Tue, Dec 13, 2011 at 10:20 AM, Nikita Popov <nikita.ppv@googlemail.com>wrote:
>
> > […]



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #56906 — Laruence — 2011-12-13T09:42:43+00:00

URL: https://externals.io/message/56901#56906 · In reply to: #56902

Hi:
  thanks for pointing this out.
  yes, maybe 5.4.1

thanks


> This can't go into PHP 5.4.0 in any case, because it is a feature
> addition and the release is already in RC.
>
> Nikita
>
> 
> > […]



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #56907 — Oleg Oshmyan — 2011-12-13T13:15:49+00:00

URL: https://externals.io/message/56901#56907 · In reply to: #56901

> Call for voting about the const array/string derefernce RFC now.
> 
> you can find more info here:
> https://wiki.php.net/rfc/constdereference#vote

I have always wondered why array dereference does not just work on
arbitrary expressions in PHP like other operators do. Even with the
latest modification that allows dereferencing function calls, this works:

    md5('')[0]

but this results in a parse error (syntax error, unexpected '['):

    (md5(''))[0]

Then there are expressions like ('a'.'b')[0], all sorts of combinations
of operators... Why not just treat any 'expression[expression]' as an
array dereference as other languages do?

> > […]
> 
> "foobar"["foo"] - Why not "undefined index"?

"foo" is converted to an integer, yielding zero. 'Undefined index' seems
to make more sense to me but PHP 5.3 behaves the same way.

-- 
Oleg

---

## #56908 — Patrick ALLAERT — 2011-12-13T13:37:13+00:00

URL: https://externals.io/message/56901#56908 · In reply to: #56902

2011/12/13 Nikita Popov <nikita.ppv@googlemail.com>:
> This can't go into PHP 5.4.0 in any case, because it is a feature
> addition and the release is already in RC.

+1

@Laruence
Can you remove the voting widget?

---

## #56909 — Pierre Joye — 2011-12-13T13:59:44+00:00

URL: https://externals.io/message/56901#56909 · In reply to: #56908

> 2011/12/13 Nikita Popov <nikita.ppv@googlemail.com>:
> > […]
>
> +1
>
> @Laruence
> Can you remove the voting widget?

I would reset the vote and make the vote for this change to apply to
trunk instead.

There is no reason to delay this decision, even if it is too late for 5.4 :)

Cheers,
-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

---

## #56916 — Laruence — 2011-12-14T02:34:22+00:00

URL: https://externals.io/message/56901#56916 · In reply to: #56909

> 
> > […]
>
> I would reset the vote and make the vote for this change to apply to
> trunk instead.
>
> There is no reason to delay this decision, even if it is too late for 5.4 :)
>
> Cheers,
> --
> Pierre
>
> @pierrejoye | http://blog.thepimp.net | http://www.libgd.org


only for trunk?

 thanks

-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #56919 — Laruence — 2011-12-14T11:19:28+00:00

URL: https://externals.io/message/56901#56919 · In reply to: #56909

> 
> > […]
>
> I would reset the vote and make the vote for this change to apply to
> trunk instead.
>
> There is no reason to delay this decision, even if it is too late for 5.4 :)
>
> Cheers,
> --
> Pierre
>
> @pierrejoye | http://blog.thepimp.net | http://www.libgd.org

Hi, done, now only voting for trunk :)

thanks

-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #56920 — Pierre Joye — 2011-12-14T11:25:59+00:00

URL: https://externals.io/message/56901#56920 · In reply to: #56919

post again as a top thread with this point being clarified please :)


> 
> > […]
>
> Hi, done, now only voting for trunk :)
>
> thanks
>
> --
> Laruence  Xinchen Hui
> http://www.laruence.com/



-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

---

## #57105 — Laruence — 2011-12-27T02:36:25+00:00

URL: https://externals.io/message/56901#57105 · In reply to: #56920

Hi:
   I have reset the vote, only vote for trunk now.

   https://wiki.php.net/rfc/constdereference

thanks


> post again as a top thread with this point being clarified please :)
>
> 
> > […]
>
>
>
> --
> Pierre
>
> @pierrejoye | http://blog.thepimp.net | http://www.libgd.org



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #57108 — Stas Malyshev — 2011-12-27T08:38:06+00:00

URL: https://externals.io/message/56901#57108 · In reply to: #57105

Hi!

> Hi:
>     I have reset the vote, only vote for trunk now.
>
>     https://wiki.php.net/rfc/constdereference
>

What happens in your patch if something like ['foo', 'bar'][1] is used 
in write context?

-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #57109 — Laruence — 2011-12-27T09:26:45+00:00

URL: https://externals.io/message/56901#57109 · In reply to: #57108

> Hi!
>
>
> > […]
>
> What happens in your patch if something like ['foo', 'bar'][1] is used in
> write context?
>
this patch will not allow that, in write context lead to syntax error.
> --
> Stanislav Malyshev, Software Architect
> SugarCRM: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
>
>
> --
> 
> 
>



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #57116 — Dmitri Snytkine — 2011-12-27T13:15:25+00:00

URL: https://externals.io/message/56901#57116

No sure who can and cannot vote, I don't see any way for me to vote.

My opinion that it’s a good idea to have array and string dereference. 
One feature however, looks odd, like it does not belong here:
echo "foobar"["foo"][0] // output f

Does it look odd to anyone else? I mean, this sort of thing can be added but it just looks like a separate feature alltogether.


Dmitri Snytkine
Web Developer
Ultra Logistics, Inc.
Phone: (888) 220-4640 x 2097
Fax: (888) 795-6642
E-Mail: dsnytkine@ultralogistics.com
Web: www.ultralogistics.com

"A Top 100 Logistics I.T. Provider in 2011"


-----Original Message-----
From: laruence@gmail.com [mailto:laruence@gmail.com] On Behalf Of Laruence
Sent: Monday, December 26, 2011 9:36 PM
To: Pierre Joye
Cc: Patrick ALLAERT; Nikita Popov; PHP Internals
Subject: Re: [PHP-DEV] [RFC]Call for voting about const array/string dereference

Hi:
   I have reset the vote, only vote for trunk now.

   https://wiki.php.net/rfc/constdereference

thanks


> post again as a top thread with this point being clarified please :)
>
> 
> > […]
>
>
>
> --
> Pierre
>
> @pierrejoye | http://blog.thepimp.net | http://www.libgd.org



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #57117 — Ferenc Kovacs — 2011-12-27T13:24:24+00:00

URL: https://externals.io/message/56901#57117 · In reply to: #57116

On Tue, Dec 27, 2011 at 2:15 PM, Dmitri Snytkine <
dsnytkine@ultralogistics.com> wrote:

> No sure who can and cannot vote, I don't see any way for me to vote.
>

https://wiki.php.net/rfc/voting
currently the following two groups can vote:
- people having php.net svn account
- people having a wiki account and manually granted with the voters group
membership


>
> My opinion that it’s a good idea to have array and string dereference.
> One feature however, looks odd, like it does not belong here:
> echo "foobar"["foo"][0] // output f
>
> Does it look odd to anyone else? I mean, this sort of thing can be added
> but it just looks like a separate feature alltogether.
>

which part seems odd to you?
this rfc and the proposed patch doesn't introduce any new behavior, just
allows using "foobar" everywhere where you could use $foobar = "foobar"
I guess you found it odd that
$foobar = "foobar";
echo $foobar["foo"];

prints 'f', but that's not a new feature, this is how php works currently.
we had a discussion about that recently, and AFAIK in the latest 5.4, a
warning will be triggered if you try to reference a string offset using a
string index.

the scalar referencing proposed here should (and AFAIK it does) behave
exactly the same as it would work if a variable with the same value would
be used.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

---

## #57118 — Dmitri Snytkine — 2011-12-27T13:42:00+00:00

URL: https://externals.io/message/56901#57118

Odd how substring can be used as index of string. 

Dmitri Snytkine
Web Developer
Ultra Logistics, Inc.
Phone: (888) 220-4640 x 2097
Fax: (888) 795-6642
E-Mail: dsnytkine@ultralogistics.com
Web: www.ultralogistics.com

"A Top 100 Logistics I.T. Provider in 2011"


-----Original Message-----
From: Ferenc Kovacs [mailto:tyra3l@gmail.com] 
Sent: Tuesday, December 27, 2011 8:24 AM
To: Dmitri Snytkine
Cc: Laruence; Pierre Joye; Patrick ALLAERT; Nikita Popov; PHP Internals
Subject: Re: [PHP-DEV] [RFC]Call for voting about const array/string dereference

On Tue, Dec 27, 2011 at 2:15 PM, Dmitri Snytkine <
dsnytkine@ultralogistics.com> wrote:

> No sure who can and cannot vote, I don't see any way for me to vote.
>

https://wiki.php.net/rfc/voting
currently the following two groups can vote:
- people having php.net svn account
- people having a wiki account and manually granted with the voters group
membership


>
> My opinion that it’s a good idea to have array and string dereference.
> One feature however, looks odd, like it does not belong here:
> echo "foobar"["foo"][0] // output f
>
> Does it look odd to anyone else? I mean, this sort of thing can be added
> but it just looks like a separate feature alltogether.
>

which part seems odd to you?
this rfc and the proposed patch doesn't introduce any new behavior, just
allows using "foobar" everywhere where you could use $foobar = "foobar"
I guess you found it odd that
$foobar = "foobar";
echo $foobar["foo"];

prints 'f', but that's not a new feature, this is how php works currently.
we had a discussion about that recently, and AFAIK in the latest 5.4, a
warning will be triggered if you try to reference a string offset using a
string index.

the scalar referencing proposed here should (and AFAIK it does) behave
exactly the same as it would work if a variable with the same value would
be used.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

---

## #57121 — Ferenc Kovacs — 2011-12-27T14:53:30+00:00

URL: https://externals.io/message/56901#57121 · In reply to: #57118

On Tue, Dec 27, 2011 at 2:42 PM, Dmitri Snytkine <
dsnytkine@ultralogistics.com> wrote:

> Odd how substring can be used as index of string.


oh, I see where the confusion comes from.
the reason why "foobar"["foo"] returns 'f' isn't that "foo" is a substring
of "foobar", but that "foo" will be casted to int, which will result in
"foobar"[0], which in turn will result in 'f'
and "foobar"["3 apples"] would return 'b' for example.
it's an unexpected behavior for many people, but it is how it works and we
even documented this.
as I mentioned in my previous mail, we will try to make this a little bit
more noisy, as this can lead to hard to spot bugs.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu
