]> granicus.if.org Git - php/commitdiff
Treat numeric strings as numbers in the increment operator
authorZeev Suraski <zeev@php.net>
Thu, 10 May 2001 12:58:31 +0000 (12:58 +0000)
committerZeev Suraski <zeev@php.net>
Thu, 10 May 2001 12:58:31 +0000 (12:58 +0000)
Zend/zend_operators.c

index 713177c380467da6d6783313f8ddc46fc51a7a51..11d72f6dc4da3a97e038d464a89f74c181912933 100644 (file)
@@ -1431,8 +1431,32 @@ ZEND_API int increment_function(zval *op1)
                        op1->value.lval = 1;
                        op1->type = IS_LONG;
                        break;
-               case IS_STRING: /* Perl style string increment */
-                       increment_string(op1);
+               case IS_STRING: {
+                               long lval;
+                               double dval;
+                               char *strval = op1->value.str.val;
+
+                               switch (is_numeric_string(strval, op1->value.str.len, &lval, &dval)) {
+                                       case IS_LONG:
+                                               op1->value.lval = lval+1;
+                                               op1->type = IS_LONG;
+                                               efree(strval);
+                                               break;
+                                       case IS_DOUBLE:
+                                               op1->value.dval = dval+1;
+                                               op1->type = IS_DOUBLE;
+                                               efree(strval);
+                                               break;
+#if 0
+                                       case FLAG_IS_BC:
+                                               /* Not implemented */
+#endif
+                                       default:
+                                               /* Perl style string increment */
+                                               increment_string(op1);
+                                               break;
+                               }
+                       }
                        break;
                default:
                        return FAILURE;