RE: [PHP-DEV] foreach() for strings

2011-06-23 Thread John Crenshaw
> -Original Message- > From: Jan Schneider [mailto:j...@horde.org] > > And if that very same string that's supposed to be an array is > processed using the $var[$n] syntax nowadays is any different? It's > not, you won't get an error message for that either, and it's the same > amoun

Re: [PHP-DEV] foreach() for strings

2011-06-23 Thread Jan Schneider
Zitat von Larry Garfield : On 06/20/2011 10:25 AM, John Crenshaw wrote: Doing this with an explicit iterator object is a fine idea. The syntax becomes something like: foreach(new TextIterator($s, 'UTF8') as $pos=>$c) { ... } On the other hand, I think that trying to support iteration wi

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Larry Garfield
On 06/20/2011 10:25 AM, John Crenshaw wrote: Doing this with an explicit iterator object is a fine idea. The syntax becomes something like: foreach(new TextIterator($s, 'UTF8') as $pos=>$c) { ... } On the other hand, I think that trying to support iteration without using an iterator objec

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Tomas Kuliavas
2011.06.22 14:14 Reindl Harald rašė: > Am 22.06.2011 07:24, schrieb Tomas Kuliavas: >> 2011.06.21 23:27 Reindl Harald rašė: >>> i do not understand any word and miss a simple str_is_utf8() >> >> Such function uses six lines in PHP. > > so why do you not post them? My lines are not public domain. T

RE: [PHP-DEV] foreach() for strings

2011-06-22 Thread Jonathan Bond-Caron
On Wed Jun 22 11:25 AM, Reindl Harald wrote: > > and php as primary web-language is missing UTF8 support in the core You have a valid point. Now onto "foreach() for strings", any other opinions? Seems like the discussion is closed and most likely should move to a RFC with some consideration ab

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
FIRST: it is terrible that one post in HTML, the next ansers on top and other answering on bottom in the same thread and that the most do not undertsand reply to the list address is enough Am 22.06.2011 17:07, schrieb Robert Eisele: > 1. The number of CHARs isn't unrelevant in a general manner i

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Robert Eisele
1. The number of CHARs isn't unrelevant in a general manner. It depents on the application, even if the trend goes towards UTF8 for websites. 2. Within 10 years, you could have come to a working solution which could please us all. 3. Stop flaming and focus on your other day-job instead. 2011/6/2

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Ferenc Kovacs
On Wed, Jun 22, 2011 at 4:52 PM, Reindl Harald wrote: > > > Am 22.06.2011 16:49, schrieb Ferenc Kovacs: > > after 10 years i want solutions where it is not the road to hell > using any > > string function on user-input and since PHP6 seems to be quite dead > > it feels there will never

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 16:49, schrieb Ferenc Kovacs: > after 10 years i want solutions where it is not the road to hell using any > string function on user-input and since PHP6 seems to be quite dead > it feels there will never be a trustable solution > > > you made my day. > boy :) after f

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Ferenc Kovacs
On Wed, Jun 22, 2011 at 4:08 PM, Reindl Harald wrote: > > > Am 22.06.2011 16:06, schrieb Rasmus Lerdorf: > > On 06/22/2011 07:01 AM, Reindl Harald wrote: > >> > >> > >> Am 22.06.2011 15:57, schrieb Rasmus Lerdorf: > >> > >>> There is obviously no way to tell if "hello" is UTF-8 or ISO-8859-1. It >

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 16:06, schrieb Rasmus Lerdorf: > On 06/22/2011 07:01 AM, Reindl Harald wrote: >> >> >> Am 22.06.2011 15:57, schrieb Rasmus Lerdorf: >> >>> There is obviously no way to tell if "hello" is UTF-8 or ISO-8859-1. It >>> is technically impossible since the two are identical in that range.

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Rasmus Lerdorf
On 06/22/2011 07:01 AM, Reindl Harald wrote: > > > Am 22.06.2011 15:57, schrieb Rasmus Lerdorf: > >> There is obviously no way to tell if "hello" is UTF-8 or ISO-8859-1. It >> is technically impossible since the two are identical in that range. > > yes and so this will not work > > and as long

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 15:57, schrieb Rasmus Lerdorf: > There is obviously no way to tell if "hello" is UTF-8 or ISO-8859-1. It > is technically impossible since the two are identical in that range. yes and so this will not work and as long PHP has on million places troubles with UTF8 it would be hardl

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 15:55, schrieb Olivier Hill: > Please change your tone. > Thank you the tonhe is quite correct for peopole who think a quick 3 liner will do the job of UTF8 detection which it does not and there you can read the manual as often you want signature.asc Description: OpenPGP digit

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Rasmus Lerdorf
On 06/22/2011 06:52 AM, Reindl Harald wrote: > > > Am 22.06.2011 15:45, schrieb Lars Schultz: >> Am 22.06.2011 15:40, schrieb Reindl Harald: >>> and why this will not return true if $str is ISO-8859-1? >> If you RTFM (in your jargon) you would know. >> >> http://ch.php.net/manual/en/function.html

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Olivier Hill
Please change your tone. Thank you. Olivier -- http://www.olivierhill.ca/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 15:45, schrieb Lars Schultz: > Am 22.06.2011 15:40, schrieb Reindl Harald: >> and why this will not return true if $str is ISO-8859-1? > If you RTFM (in your jargon) you would know. > > http://ch.php.net/manual/en/function.htmlspecialchars.php (Return value > Section) i read the

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Anthony Ferrara
> and why this will not return true if $str is ISO-8859-1? For lower 7 bit characters (code points <= 127) it would return true. But if there is a single higher character (outside of ascii), it would only return true if the byte sequences follow UTF-8 semantics. So it would return false if ISO-88

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Lars Schultz
Am 22.06.2011 15:40, schrieb Reindl Harald: and why this will not return true if $str is ISO-8859-1? If you RTFM (in your jargon) you would know. http://ch.php.net/manual/en/function.htmlspecialchars.php (Return value Section) -- PHP Internals - PHP Runtime Development Mailing List To unsub

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 15:30, schrieb Gustavo Lopes: > Em Wed, 22 Jun 2011 13:21:10 +0100, Reindl Harald > escreveu: > >> Am 22.06.2011 14:14, schrieb Gustavo Lopes: >>> It's actually 3 lines: >>> >>> function str_is_utf8($str) { >>> return $str == "" || htmlspecialchars($str, 0, "UTF-8"); >>> } >>

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Gustavo Lopes
Em Wed, 22 Jun 2011 13:21:10 +0100, Reindl Harald escreveu: Am 22.06.2011 14:14, schrieb Gustavo Lopes: It's actually 3 lines: function str_is_utf8($str) { return $str == "" || htmlspecialchars($str, 0, "UTF-8"); } WTF should this do? this won't return boolean The reason it works

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Kalle Sommer Nielsen
2011/6/22 Reindl Harald : > WTF should this do? > this won't return boolean It's an expression, so its evaluated result is a boolean hence why it makes sense -- regards, Kalle Sommer Nielsen ka...@php.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://w

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 14:14, schrieb Gustavo Lopes: > Em Wed, 22 Jun 2011 12:14:40 +0100, Reindl Harald > escreveu: >> Am 22.06.2011 07:24, schrieb Tomas Kuliavas: >>> 2011.06.21 23:27 Reindl Harald rašė: i do not understand any word and miss a simple str_is_utf8() >>> >>> Such function uses six l

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Gustavo Lopes
Em Wed, 22 Jun 2011 12:14:40 +0100, Reindl Harald escreveu: Am 22.06.2011 07:24, schrieb Tomas Kuliavas: 2011.06.21 23:27 Reindl Harald rašė: i do not understand any word and miss a simple str_is_utf8() Such function uses six lines in PHP. so why do you not post them?t It's actually 3

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 07:24, schrieb Tomas Kuliavas: > 2011.06.21 23:27 Reindl Harald rašė: >> i do not understand any word and miss a simple str_is_utf8() > > Such function uses six lines in PHP. so why do you not post them? > You can write your own. no i can not as said > I need locale insensitiv

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Tomas Kuliavas
2011.06.21 23:27 Reindl Harald rašė: > i do not understand any word and miss a simple str_is_utf8() Such function uses six lines in PHP. You can write your own. I need locale insensitive casecmp, typecasting to unsigned 32bit int and bunch of other functions in PHP. Do I have wait for PHP implemen

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Reindl Harald
Am 21.06.2011 22:19, schrieb Tomas Kuliavas: > 2011.06.21 20:51 Reindl Harald rašė: >>> utf-8 is strict format. If you expect utf-8 and someone submits >>> something >>> else, you can tell that without any string function. You can verify >>> utf-8 >>> strings in pcre. You can convert nbspace to r

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Tomas Kuliavas
2011.06.21 20:51 Reindl Harald rašė: >> utf-8 is strict format. If you expect utf-8 and someone submits >> something >> else, you can tell that without any string function. You can verify >> utf-8 >> strings in pcre. You can convert nbspace to regular space, if you want. >> utf-8 does not have any

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Reindl Harald
Am 21.06.2011 19:12, schrieb Tomas Kuliavas: and this naive attitude is the root of most security problems! why do you believe that every client submission is coming over your form or generally over anything you can control? >>> that doesn't matter here, Tomas just c

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Tomas Kuliavas
2011.06.21 19:24 Reindl Harald rašė: > > > Am 21.06.2011 18:22, schrieb Ferenc Kovacs: >> On Tue, Jun 21, 2011 at 6:14 PM, Reindl Harald >> wrote: >> >>> >>> >>> Am 21.06.2011 17:55, schrieb Tomas Kuliavas: >>> They submit it in utf-8 only if your html form allows them to do that or

RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread John Crenshaw
> From: Pierre Joye [mailto:pierre@gmail.com] > > On Tue, Jun 21, 2011 at 4:38 PM, John Crenshaw > > wrote: > > > This mindset is fundamentally broken. You can call it a byte array all you > > want, but the truth is that 99.999% of the time, when a developer is using > > a string they nee

RE: RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread John Crenshaw
> They submit it in utf-8 only if your html form allows them to do that or > they don't follow html specification and try to exploit your form. If no explicit encoding is given, all modern browsers will attempt to "autodetect" the encoding based on the page contents, often with unpredictable res

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Ferenc Kovacs
On Tue, Jun 21, 2011 at 6:24 PM, Reindl Harald wrote: > > > Am 21.06.2011 18:22, schrieb Ferenc Kovacs: > > On Tue, Jun 21, 2011 at 6:14 PM, Reindl Harald >wrote: > > > >> > >> > >> Am 21.06.2011 17:55, schrieb Tomas Kuliavas: > >> > >>> They submit it in utf-8 only if your html form allows them

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Reindl Harald
Am 21.06.2011 18:22, schrieb Ferenc Kovacs: > On Tue, Jun 21, 2011 at 6:14 PM, Reindl Harald wrote: > >> >> >> Am 21.06.2011 17:55, schrieb Tomas Kuliavas: >> >>> They submit it in utf-8 only if your html form allows them to do that or >>> they don't follow html specification and try to exploit

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Ferenc Kovacs
On Tue, Jun 21, 2011 at 6:14 PM, Reindl Harald wrote: > > > Am 21.06.2011 17:55, schrieb Tomas Kuliavas: > > > They submit it in utf-8 only if your html form allows them to do that or > > they don't follow html specification and try to exploit your form. Set > > form input charset to iso-8859-1 an

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Reindl Harald
Am 21.06.2011 17:55, schrieb Tomas Kuliavas: > They submit it in utf-8 only if your html form allows them to do that or > they don't follow html specification and try to exploit your form. Set > form input charset to iso-8859-1 and your nbspace will take only one byte. and this naive attitude i

Re: RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread Arvids Godjuks
As a userland developer due to my geographical nature i have to work with 3 languages constantly - english, russian (cyryllic) and latvian (witch has it's own share of non latin characters). I end up using utf-8 in every project. And some give me a headake of dealing with text parsing. mb_string co

RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread Tomas Kuliavas
2011.06.21 17:38 John Crenshaw rašė: > Pierre Joye wrote: >> On Tue, Jun 21, 2011 at 1:33 PM, Lester Caine >> wrote: >>> Pierre Joye wrote: > > It depended on ICU there, and I would be against making a core thing > in >> PHP 5.x depend on ICU. It can and should be done a

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Pierre Joye
On Tue, Jun 21, 2011 at 4:38 PM, John Crenshaw wrote: > This mindset is fundamentally broken. You can call it a byte array all you > want, but the truth is that 99.999% of the time, when a developer is using a > string they need it for characters, not for bytes Let me rephrase: For backward c

RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread John Crenshaw
Pierre Joye wrote: > On Tue, Jun 21, 2011 at 1:33 PM, Lester Caine wrote: >> Pierre Joye wrote: It depended on ICU there, and I would be against making a core thing in > PHP 5.x depend on ICU. >>> >>> It can and should be done as part of intl, actually. >>> >>> But that's somehow u

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Lester Caine
Pierre Joye wrote: On Tue, Jun 21, 2011 at 1:33 PM, Lester Caine wrote: Pierre Joye wrote: It depended on ICU there, and I would be against making a core thing in PHP 5.x depend on ICU. It can and should be done as part of intl, actually. But that's somehow unrelated to the proposal her

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Pierre Joye
On Tue, Jun 21, 2011 at 1:33 PM, Lester Caine wrote: > Pierre Joye wrote: >>> >>> It depended on ICU there, and I would be against making a core thing in >>> >  PHP 5.x depend on ICU. >> >> It can and should be done as part of intl, actually. >> >> But that's somehow unrelated to the proposal here

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Lester Caine
Pierre Joye wrote: It depended on ICU there, and I would be against making a core thing in > PHP 5.x depend on ICU. It can and should be done as part of intl, actually. But that's somehow unrelated to the proposal here, as it is about byte, not characters :) I believe this may be where some

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Pierre Joye
On Tue, Jun 21, 2011 at 12:53 PM, Derick Rethans wrote: > It depended on ICU there, and I would be against making a core thing in > PHP 5.x depend on ICU. It can and should be done as part of intl, actually. But that's somehow unrelated to the proposal here, as it is about byte, not characters

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Derick Rethans
On Mon, 20 Jun 2011, Stas Malyshev wrote: > On 6/20/11 9:15 AM, John Crenshaw wrote: > > > From: Ilia Alshanetsky [mailto:i...@prohost.org] > > > > > > As long as it works on a premise that a "string" is a byte array > > > and each element represents 1 byte, +1 from me. > > > > Code written on t

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Stas Malyshev
Hi! On 6/20/11 9:15 AM, John Crenshaw wrote: From: Ilia Alshanetsky [mailto:i...@prohost.org] As long as it works on a premise that a "string" is a byte array and each element represents 1 byte, +1 from me. Code written on this premise is almost always bug central when people finally get arou

RE: [PHP-DEV] foreach() for strings

2011-06-20 Thread John Crenshaw
> From: Ilia Alshanetsky [mailto:i...@prohost.org] > > As long as it works on a premise that a "string" is a byte array and > each element represents 1 byte, +1 from me. Code written on this premise is almost always bug central when people finally get around to realizing why they really do need

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Stas Malyshev
Hi! foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for strings, too. I'm not sure how you'd implement such thing, but then I think things like next(), end(), etc. should work too... -- Sta

RE: [PHP-DEV] foreach() for strings

2011-06-20 Thread John Crenshaw
> -Original Message- > From: Lee davis [mailto:leedavi...@gmail.com] > Sent: Monday, June 20, 2011 9:12 AM > To: Robert Eisele > Cc: internals@lists.php.net > Subject: Re: [PHP-DEV] foreach() for strings > > I think this would be quite a useful feature, and am I

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Ilia Alshanetsky
As long as it works on a premise that a "string" is a byte array and each element represents 1 byte, +1 from me. On Mon, Jun 20, 2011 at 7:27 AM, Robert Eisele wrote: > foreach() has many functions, looping over arrays, objects and implementing > the iterator interface. I think it's also quite in

RE: [PHP-DEV] foreach() for strings

2011-06-20 Thread Jonathan Bond-Caron
On Mon Jun 20 09:11 AM, Lee davis wrote: > > Could we also use current(), next() and key() for iteration of strings? > > $string = 'string'; > while ($char = current($string)) > { > echo key($string) // Would output the offset position I assume 0,1,2 > etc?? > echo $char // outputs eac

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Lee davis
I think this would be quite a useful feature, and am In favor of it. However, I think caution should be taken when shifting array utilities out of their remit and allowing them to manipulate / traverse other data types. You may see the floodgates opening for more request to adapt array functions fo

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Pierre Joye
hi Robert, I would go with a RFC for that one, at least to document/cover edge cases to help the doc team to properly document this change if it gets approved. Thanks for your work so far! On Mon, Jun 20, 2011 at 1:27 PM, Robert Eisele wrote: > foreach() has many functions, looping over arrays,

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Pierre Joye
2011/6/20 Johannes Schlüter : > On Mon, 2011-06-20 at 13:27 +0200, Robert Eisele wrote: >> foreach() has many functions, looping over arrays, objects and implementing >> the iterator interface. I think it's also quite intuitive to use foreach() >> for strings, too. > > I would prefer a TextIterator

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Derick Rethans
On Mon, 20 Jun 2011, Robert Eisele wrote: > 2011/6/20 Derick Rethans > > > On Mon, 20 Jun 2011, Robert Eisele wrote: > > > > > foreach() has many functions, looping over arrays, objects and > > > implementing the iterator interface. I think it's also quite > > > intuitive to use foreach() for

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Derick Rethans
On Mon, 20 Jun 2011, Johannes Schlüter wrote: > On Mon, 2011-06-20 at 13:27 +0200, Robert Eisele wrote: > > foreach() has many functions, looping over arrays, objects and implementing > > the iterator interface. I think it's also quite intuitive to use foreach() > > for strings, too. > > I would

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Johannes Schlüter
On Mon, 2011-06-20 at 13:27 +0200, Robert Eisele wrote: > foreach() has many functions, looping over arrays, objects and implementing > the iterator interface. I think it's also quite intuitive to use foreach() > for strings, too. I would prefer a TextIterator as we had in the old PHP 6 as this al

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Robert Eisele
2011/6/20 Derick Rethans > On Mon, 20 Jun 2011, Robert Eisele wrote: > > > foreach() has many functions, looping over arrays, objects and > implementing > > the iterator interface. I think it's also quite intuitive to use > foreach() > > for strings, too. > > > If you want to implement a parser i

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Derick Rethans
On Mon, 20 Jun 2011, Robert Eisele wrote: > foreach() has many functions, looping over arrays, objects and implementing > the iterator interface. I think it's also quite intuitive to use foreach() > for strings, too. > If you want to implement a parser in PHP, you have to go the way with for + >