Commit:    133f610bb18831a6d64061cd6e4e7f7779bf1581
Author:    Lars Strojny <lstro...@php.net>         Sun, 2 Sep 2012 14:52:05 
+0200
Parents:   89948c7fbe487e5d75f7b02fe0c29238f556f341
Branches:  PHP-5.4

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=133f610bb18831a6d64061cd6e4e7f7779bf1581

Log:
Allow null as a default value for length in mb_substr() and mb_strcut()

Changed paths:
  M  NEWS
  M  ext/mbstring/mbstring.c
  M  ext/mbstring/tests/mb_str_functions_opt-parameter.phpt


Diff:
diff --git a/NEWS b/NEWS
index 60bb235..836cf97 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,10 @@ PHP                                                          
              NEWS
   . Bug #62987 (Assigning to ArrayObject[null][something] overrides all 
     undefined variables). (Laruence)
 
+- mbstring:
+  . Allow passing null as a default value to mb_substr() and mb_strcut(). Patch
+    by Alexander Moskaliov via GitHub PR #133. (Lars)
+
 ?? ??? 2012, PHP 5.4.7
 
 - Core:
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 0d2b53a..76654ed 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -2715,9 +2715,10 @@ PHP_FUNCTION(mb_substr)
        char *str, *encoding;
        long from, len;
        int mblen, str_len, encoding_len;
+       zval **z_len = NULL;
        mbfl_string string, result, *ret;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", &str, 
&str_len, &from, &len, &encoding, &encoding_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|Zs", &str, 
&str_len, &from, &z_len, &encoding, &encoding_len) == FAILURE) {
                return;
        }
 
@@ -2736,8 +2737,11 @@ PHP_FUNCTION(mb_substr)
        string.val = (unsigned char *)str;
        string.len = str_len;
 
-       if (argc < 3) {
+       if (argc < 3 || Z_TYPE_PP(z_len) == IS_NULL) {
                len = str_len;
+       } else {
+               convert_to_long_ex(z_len);
+               len = Z_LVAL_PP(z_len);
        }
 
        /* measures length */
@@ -2788,13 +2792,14 @@ PHP_FUNCTION(mb_strcut)
        char *encoding;
        long from, len;
        int encoding_len;
+       zval **z_len = NULL;
        mbfl_string string, result, *ret;
 
        mbfl_string_init(&string);
        string.no_language = MBSTRG(language);
        string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", (char 
**)&string.val, (int **)&string.len, &from, &len, &encoding, &encoding_len) == 
FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|Zs", (char 
**)&string.val, (int **)&string.len, &from, &z_len, &encoding, &encoding_len) 
== FAILURE) {
                return;
        }
 
@@ -2806,8 +2811,11 @@ PHP_FUNCTION(mb_strcut)
                }
        }
 
-       if (argc < 3) {
+       if (argc < 3 || Z_TYPE_PP(z_len) == IS_NULL) {
                len = string.len;
+       } else {
+               convert_to_long_ex(z_len);
+               len = Z_LVAL_PP(z_len);
        }
 
        /* if "from" position is negative, count start position from the end
diff --git a/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt 
b/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt
index e4a235d..5fb642f 100644
--- a/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt
+++ b/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt
@@ -28,5 +28,3 @@ baz
 baz
 foo
 ==DONE==
---XFAIL--
-mb functions fail to allow null instead of actual value


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to