patch to allow negative string offsets in {}
| From: | val khokhlov | Date: | Sat, 30 Jul 2005 10:40:23 +0000 |
| Subject: | patch to allow negative string offsets in {} | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-17467@lists.php.net to get a copy of this message | ||
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
--- 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);
--- 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);