patch to allow negative string offsets in {}

php.internals

val khokhlov

21 years ago
Hello, a small patch that allows using negative value for offset in $string{offset} $string = "test"; $string{-1} -> last 't' $string{-2} -> 's' and so on... ================<< --- zend_execute.c Mon Jul 18 11:20:19 2005 +++ /home/val/src/php/php5.1/php-src/Zend/zend_execute.c Sat Jul 30 13:33:57 2005 @@ -1097,6 +1097,7 @@ result->str_offset.str = container; PZVAL_LOCK(container); result->str_offset.offset = dim->value.lval; + if (dim->value.lval < 0) result->str_offset.offset += container->value.str.len; result->var.ptr_ptr = NULL; if (type == BP_VAR_R || type == BP_VAR_IS) { AI_USE_PTR(result->var); ================<<
-- Best regards, val mailto:val@vk.kiev.ua

l0t3k

21 years ago
val, you dont clamp at the lower bound. suppose offset == -LONG_MAX l0t3k "val khokhlov" <val@vk.kiev.ua> wrote in message news:446750995.20050730134023@vk.kiev.ua...

Stefan Esser

21 years ago
cshmoove@bellsouth.net wrote:
>val, > you dont clamp at the lower bound. suppose offset == -LONG_MAX > >
This would result in a negative offset value and the execution logic of PHP will tell you that this is not a valid string offset....