Edit report at https://bugs.php.net/bug.php?id=60725&edit=1
ID: 60725
User updated by: a dot dobkin at drweb dot com
Reported by: a dot dobkin at drweb dot com
Summary: zend_parse_parameters(): Incorrect parsing of the
first parameter
Status: Open
Type: Bug
Package: Unknown/Other Function
Operating System: fedora core 16 x64
PHP Version: 5.3.9
Block user comment: N
Private report: N
New Comment:
Incorrect parsing first parameter when type_spec = "sls" (e.g.)
zend_parse_parameter() return string length as 0, always. See example #1 and #2:
PHP Warning: First parameter: 'first' and it len: 0 in Command line code on
line 1
Previous Comments:
------------------------------------------------------------------------
[2012-01-12 11:11:16] idlesign at yandex dot ru
@felipe, do you read what subject says?
Please elaborate on "'l' expects a 'long', not an 'int'" of yours and on how
does it relate to the problem.
This ticket is about string length param is set to 0 upon specified
circumstances.
------------------------------------------------------------------------
[2012-01-12 10:59:59] [email protected]
'l' expects a 'long', not an 'int'
------------------------------------------------------------------------
[2012-01-12 10:57:56] a dot dobkin at drweb dot com
Description:
------------
Incorrect parsing of the first parameter if it's
has type of 'string' and one of next parameter has type of 'long'.
Function zend_parse_parameters() always return string length as 0 of first
parameter. Error is present in versions 5.3.7-5.3.9. In version 5.3.6 there is
no error
On php v 5.3.6 it's correctly works
Example 1 (Error):
PHP_FUNCTION(test_parse_parameters) {
char *p_str1 = NULL;
char *p_str2 = NULL;
int p_long;
int p_str1_len;
int p_str2_len;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls",
&p_str1, &p_str1_len, &p_long, &p_str2, &p_str2_len)) {
return;
}
zend_error(E_WARNING, "First parameter: '%s' and it len: %d", p_str1,
p_str1_len);
zend_error(E_WARNING, "Second parameter: '%d'", p_long);
zend_error(E_WARNING, "Third parameter: '%s' and it len: %d", p_str2,
p_str2_len);
}
Run:
[antonio@antonio]# php -r 'test_parse_parameters("first", 123, "third");'
Output:
>>> PHP Warning: First parameter: 'first' and it len: 0 in Command line code
>>> on
line 1 <<<
PHP Warning: Second parameter: '123' in Command line code on line 1
PHP Warning: Third parameter: 'third' and it len: 5 in Command line code on
line 1
Exemple 2 (Error):
PHP_FUNCTION(test_parse_parameters) {
char *p_str1 = NULL;
char *p_str2 = NULL;
int p_str1_len;
int p_str2_len;
int p_long;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl",
&p_str1, &p_str1_len, &p_str2, &p_str2_len, &p_long)) {
return;
}
zend_error(E_WARNING, "First parameter: '%s' and it len: %d", p_str1,
p_str1_len);
zend_error(E_WARNING, "Second parameter: '%s' and it len: %d", p_str2,
p_str2_len);
zend_error(E_WARNING, "Third parameter: '%d'", p_long);
}
Run:
[antonio@antonio]# php -r 'dwavd_init("first", "second", 123);'
Output:
>>> PHP Warning: First parameter: 'first' and it len: 0 in Command line code
>>> on
line 1 <<<
PHP Warning: Second parameter: 'second' and it len: 6 in Command line code on
line 1
PHP Warning: Third parameter: '123' in Command line code on line 1
Exemple 3 (OK):
PHP_FUNCTION(test_parse_parameters) {
char *p_str1 = NULL;
char *p_str2 = NULL;
int p_str1_len;
int p_str2_len;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&p_str1,
&p_str1_len, &p_str2, &p_str2_len)) {
return;
}
zend_error(E_WARNING, "First parameter: '%s' and it len: %d", p_str1,
p_str1_len);
zend_error(E_WARNING, "Second parameter: '%s' and it len: %d", p_str2,
p_str2_len);
}
Run:
[antonio@antonio]# php -r 'test_parse_parameters("first", "second");'
Output:
PHP Warning: First parameter: 'first' and it len: 5 in Command line code on
line 1
PHP Warning: Second parameter: 'second' and it len: 6 in Command line code on
line 1
Exemple 4 (OK):
PHP_FUNCTION(test_parse_parameters) {
char *p_str1 = NULL;
char *p_str2 = NULL;
int p_str1_len;
int p_str2_len;
int p_long;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss",
&p_long, &p_str1, &p_str1_len, &p_str2, &p_str2_len)) {
return;
}
zend_error(E_WARNING, "First parameter: '%d'", p_long);
zend_error(E_WARNING, "Second parameter: '%s' and it len: %d", p_str1,
p_str1_len);
zend_error(E_WARNING, "Third parameter: '%s' and it len: %d", p_str2,
p_str2_len);
}
Run:
[antonio@antonio]# php -r 'test_parse_parameters(123, "second", "third");'
Output:
PHP Warning: First parameter: '123' in Command line code on line 1
PHP Warning: Second parameter: 'second' and it len: 5 in Command line code on
line 1
PHP Warning: Third parameter: 'third' and it len: 6 in Command line code on
line 1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60725&edit=1