Edit report at https://bugs.php.net/bug.php?id=63535&edit=1

 ID:                 63535
 Comment by:         ni...@php.net
 Reported by:        lmpmbernardo at gmail dot com
 Summary:            zend_parse_parameters: error when signature is
                     s|ssbs
 Status:             Not a bug
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Ubuntu 12.04 LTS 32 bits
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

s|ssbs means the functions takes a string as the required first argument and 
string string bool string as optional arguments. The | just delimits required 
arguments from optional arguments. zend_parse_parameters does not specify the 
return value type (actually the return value type isn't specified anywhere, you 
just return it.)


Previous Comments:
------------------------------------------------------------------------
[2012-11-16 13:34:57] lmpmbernardo at gmail dot com

sorry, I checked many times that I was not missing something and I don't 
understand your statement. can you please clarify? I am passing ssbs. my 
understanding is that s|ssbs means the function takes ssbs as arguments and 
returs 
s.

------------------------------------------------------------------------
[2012-11-16 01:28:57] fel...@php.net

You are specifying "s|ssbs", but it's passing args for "s|sbs".

------------------------------------------------------------------------
[2012-11-16 00:47:19] lmpmbernardo at gmail dot com

updated version; 5.3.10 is the most recent version in Ubuntu.

------------------------------------------------------------------------
[2012-11-16 00:46:13] lmpmbernardo at gmail dot com

Description:
------------
zend_parse_parameters is having trouble parsing this signature: s|ssbs; the 
error happens with the last "bs" arguments. the signature "ssbs" works well.

~$ php -v
PHP 5.3.10-1ubuntu3.4 with Suhosin-Patch (cli) (built: Sep 12 2012 19:00:43) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies


Test script:
---------------
PHP_FUNCTION(test_parse_parameters) {
  char *p_str1 = "";
  int p_str1_len;
  char *p_str2 = "";
  int p_str2_len;
  char *p_str3 = "";
  int p_str3_len;
  zend_bool b = 0;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ssbs", &p_str1, 
&p_str1_len, &p_str2,
      &p_str2_len, &b, &p_str3, &p_str3_len) == FAILURE) {
    return;
  }

  zend_error(E_WARNING, "First parameter: len[%d] value[%s]", p_str1_len, 
p_str1);
  zend_error(E_WARNING, "Second parameter: len[%d] value[%s]", p_str2_len, 
p_str2);
  zend_error(E_WARNING, "Third parameter: '%s'", b ? "TRUE" : "FALSE");
  zend_error(E_WARNING, "Fourth parameter: len[%d] value[%s]", p_str3_len, 
p_str3);

  char returnValue[256];
  char* result;
  sprintf(returnValue, "%d#%s", 0, "houston, we have a problem!");
  result = estrdup(returnValue);
  RETURN_STRING(result, 0);
}


Expected result:
----------------
lbernardo@sousel:~$ php -r 'echo test_parse_parameters("first", "second", 
FALSE, "fourth");'
PHP Warning:  First parameter: len[5] value[first] in Command line code on line 
1
PHP Warning:  Second parameter: len[6] value[second] in Command line code on 
line 1
PHP Warning:  Third parameter: 'FALSE' in Command line code on line 1
PHP Warning:  Fourth parameter: len[6] value[fourth] in Command line code on 
line 1
0#houston, we have a problem!


Actual result:
--------------
lbernardo@sousel:~$ php -r 'echo test_parse_parameters("first", "second", 
FALSE, "fourth");'
PHP Warning:  First parameter: len[5] value[first] in Command line code on line 
1
PHP Warning:  Second parameter: len[6] value[second] in Command line code on 
line 1
PHP Warning:  Third parameter: 'TRUE' in Command line code on line 1
PHP Warning:  Fourth parameter: len[769] value[(null)] in Command line code on 
line 1
0#houston, we have a problem!



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63535&edit=1

Reply via email to