Re: [PHP-DEV] Negative string offset support

2004-10-29 Thread Ilia Alshanetsky
While you are correct that invalid offset in a string will produce an 
error message. This error message is E_NOTICE, given that our default 
INI error reporting level won't display those it's arguable that very 
few people will see them and consequently do something about it.

> echo $a{strlen($a)-1}; ? is that really that bad.
It is not that bad, but it could be better. Basic tests I've ran show 
that using a strlen() is 30-40% slower and substr() is 20-25% slower 
then $a{-1}.

Ilia
Alan Knowles wrote:
I do worry that at present
$a = "a string";
$p = 0
while( $p < strlen($p) )
  .. do stuff that could do $p-- or $p++ 
  echo $a{$p};
}
at present that would produce a nice error if you went < 0.. easy to 
spot.. - if -ve was supported it could do unexpected stuff..

Regards
Alan
Ilia Alshanetsky wrote:
I am wondering what are people's opinions on adding support for 
negative string offsets that could be used to access data from the end 
of a string.

Ex. $a = "123"; echo $a[-1]; // would print 3
I don't think we should do this for arrays, since -1 and similar are 
valid array keys, which means adding this support for arrays would 
break BC.

Ilia

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


Re: [PHP-DEV] Negative string offset support

2004-10-29 Thread Alan Knowles
echo $a{strlen($a)-1}; ? is that really that bad.
I do worry that at present
$a = "a string";
$p = 0
while( $p < strlen($p) )
  .. do stuff that could do $p-- or $p++ 
  echo $a{$p};
}
at present that would produce a nice error if you went < 0.. easy to 
spot.. - if -ve was supported it could do unexpected stuff..

Regards
Alan
Ilia Alshanetsky wrote:
I am wondering what are people's opinions on adding support for 
negative string offsets that could be used to access data from the end 
of a string.

Ex. $a = "123"; echo $a[-1]; // would print 3
I don't think we should do this for arrays, since -1 and similar are 
valid array keys, which means adding this support for arrays would 
break BC.

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


Re: [PHP-DEV] Negative string offset support

2004-10-29 Thread Robert Cummings
On Fri, 2004-10-29 at 19:31, Derick Rethans wrote:
> On Fri, 29 Oct 2004, Robert Cummings wrote:
> 
> > On Fri, 2004-10-29 at 19:04, Derick Rethans wrote:
> >
> > > Yeah, [] is for arrays, {} for string indexes though I still think this
> > > should not be in, one can use substring for this. Something like a
> > > "negative string index" is IMO too much magic.
> >
> > Just as much magic as the negative start in substr() function. It would
> > be consistent with substr() precedent of negative indexes counting
> > backward from end of string.
> 
> But substr() is a *function*, that's totally different from a language
> construct which should be a generic tool, not a specific one like Ilia
> is proposing here.
> 
> > Also, everyone knows functions run slower than operators :)
> *cough*bullshit argument*cough*

Well for the amount of times you need to traverse backward in a string
it probably is a crap argument :) However it does indeed stand that
operators are processed faster than functions I would wager due to the
overhead of setting up parameters etc. Contrast is_null( $x ) versus $x
=== null, there's about 17% difference in speed. Similarly (0.0 + $x)
takes almost half the time of floatval( $x ).

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] Negative string offset support

2004-10-29 Thread Derick Rethans
On Fri, 29 Oct 2004, Robert Cummings wrote:

> On Fri, 2004-10-29 at 19:04, Derick Rethans wrote:
>
> > Yeah, [] is for arrays, {} for string indexes though I still think this
> > should not be in, one can use substring for this. Something like a
> > "negative string index" is IMO too much magic.
>
> Just as much magic as the negative start in substr() function. It would
> be consistent with substr() precedent of negative indexes counting
> backward from end of string.

But substr() is a *function*, that's totally different from a language
construct which should be a generic tool, not a specific one like Ilia
is proposing here.

> Also, everyone knows functions run slower than operators :)
*cough*bullshit argument*cough*

Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

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



Re: [PHP-DEV] Negative string offset support

2004-10-29 Thread Robert Cummings
On Fri, 2004-10-29 at 19:04, Derick Rethans wrote:
> On Fri, 29 Oct 2004, Sterling Hughes wrote:
> 
> > why not add it with the {} operators then?
> 
> Yeah, [] is for arrays, {} for string indexes though I still think this
> should not be in, one can use substring for this. Something like a
> "negative string index" is IMO too much magic.

Just as much magic as the negative start in substr() function. It would
be consistent with substr() precedent of negative indexes counting
backward from end of string. Also, everyone knows functions run slower
than operators :)

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] Negative string offset support

2004-10-29 Thread Derick Rethans
On Fri, 29 Oct 2004, Sterling Hughes wrote:

> why not add it with the {} operators then?

Yeah, [] is for arrays, {} for string indexes though I still think this
should not be in, one can use substring for this. Something like a
"negative string index" is IMO too much magic.

Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

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



Re: [PHP-DEV] Negative string offset support

2004-10-29 Thread Andi Gutmans
We haven't yet separated the semantics of {} and []. It was always planned 
but never done.
I'll put it on my TODO and hopefully will find some time to look into it.

Andi
At 04:13 PM 10/29/2004 -0400, Paul G wrote:
- Original Message -
From: "Ilia Alshanetsky" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 29, 2004 3:07 PM
Subject: [PHP-DEV] Negative string offset support
> I am wondering what are people's opinions on adding support for negative
> string offsets that could be used to access data from the end of a string.
>
> Ex. $a = "123"; echo $a[-1]; // would print 3
>
> I don't think we should do this for arrays, since -1 and similar are
> valid array keys, which means adding this support for arrays would break
BC.
this, coupled with splicing, is very useful in python. i believe it would be
very useful in php as well. agree with sterling's suggestion - it would
enable all of the functionality, rather than some.
paul
--
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] Negative string offset support

2004-10-29 Thread Paul G

- Original Message - 
From: "Ilia Alshanetsky" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 29, 2004 3:07 PM
Subject: [PHP-DEV] Negative string offset support


> I am wondering what are people's opinions on adding support for negative
> string offsets that could be used to access data from the end of a string.
>
> Ex. $a = "123"; echo $a[-1]; // would print 3
>
> I don't think we should do this for arrays, since -1 and similar are
> valid array keys, which means adding this support for arrays would break
BC.

this, coupled with splicing, is very useful in python. i believe it would be
very useful in php as well. agree with sterling's suggestion - it would
enable all of the functionality, rather than some.

paul

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



Re: [PHP-DEV] Negative string offset support

2004-10-29 Thread Ilia Alshanetsky
Sure, I have no operator preference.
Ilia
Sterling Hughes wrote:
why not add it with the {} operators then?
-sterling
On Fri, 29 Oct 2004 15:07:05 -0400, Ilia Alshanetsky <[EMAIL PROTECTED]> wrote:
I am wondering what are people's opinions on adding support for negative
string offsets that could be used to access data from the end of a string.
Ex. $a = "123"; echo $a[-1]; // would print 3
I don't think we should do this for arrays, since -1 and similar are
valid array keys, which means adding this support for arrays would break BC.
Ilia
--
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] Negative string offset support

2004-10-29 Thread Rasmus Lerdorf
Right, I was about to say that too.  If we only did it for the {} operator
it would encourage people to use that little-used operator thereby
removing a source of confusion and at the same time the BC issues are
minimal.

-Rasmus

On Fri, 29 Oct 2004, Sterling Hughes wrote:

> why not add it with the {} operators then?
>
> -sterling
>
>
> On Fri, 29 Oct 2004 15:07:05 -0400, Ilia Alshanetsky <[EMAIL PROTECTED]> wrote:
> > I am wondering what are people's opinions on adding support for negative
> > string offsets that could be used to access data from the end of a string.
> >
> > Ex. $a = "123"; echo $a[-1]; // would print 3
> >
> > I don't think we should do this for arrays, since -1 and similar are
> > valid array keys, which means adding this support for arrays would break BC.
> >
> > Ilia
> >
> > --
> > 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
>

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



Re: [PHP-DEV] Negative string offset support

2004-10-29 Thread cm
Exactly what I thought when reading the original post :)

- Michael

> why not add it with the {} operators then?
>
> -sterling
>
>
> On Fri, 29 Oct 2004 15:07:05 -0400, Ilia Alshanetsky <[EMAIL PROTECTED]>
> wrote:
>> I am wondering what are people's opinions on adding support for negative
>> string offsets that could be used to access data from the end of a
>> string.
>>
>> Ex. $a = "123"; echo $a[-1]; // would print 3
>>
>> I don't think we should do this for arrays, since -1 and similar are
>> valid array keys, which means adding this support for arrays would break
>> BC.
>>
>> Ilia
>>
>> --
>> 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
>
>

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



Re: [PHP-DEV] Negative string offset support

2004-10-29 Thread Sterling Hughes
why not add it with the {} operators then?

-sterling


On Fri, 29 Oct 2004 15:07:05 -0400, Ilia Alshanetsky <[EMAIL PROTECTED]> wrote:
> I am wondering what are people's opinions on adding support for negative
> string offsets that could be used to access data from the end of a string.
> 
> Ex. $a = "123"; echo $a[-1]; // would print 3
> 
> I don't think we should do this for arrays, since -1 and similar are
> valid array keys, which means adding this support for arrays would break BC.
> 
> Ilia
> 
> --
> 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



[PHP-DEV] Negative string offset support

2004-10-29 Thread Ilia Alshanetsky
I am wondering what are people's opinions on adding support for negative 
string offsets that could be used to access data from the end of a string.

Ex. $a = "123"; echo $a[-1]; // would print 3
I don't think we should do this for arrays, since -1 and similar are 
valid array keys, which means adding this support for arrays would break BC.

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