#26906 [Opn]: strlen returns values for non string types

From: Date: Wed, 14 Jan 2004 18:25:53 +0000
Subject: #26906 [Opn]: strlen returns values for non string types
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-53325@lists.php.net to get a copy of this message
ID: 26906 User updated by: scottmacvicar at ntlworld dot com Reported By: scottmacvicar at ntlworld dot com Status: Open Bug Type: Scripting Engine problem Operating System: All PHP Version: 4CVS-2004-01-14 (stable) New Comment: Patch diff -u zend_builtin_functions.c zend_builtin_functions.c.patched --- zend_builtin_functions.c 2003-08-28 18:06:52.000000000 +0100 +++ zend_builtin_functions.c.patched 2004-01-14 17:46:02.000000000 +0000 @@ -260,6 +260,16 @@ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { ZEND_WRONG_PARAM_COUNT(); } + switch((*str)->type) { + case IS_LONG: + case IS_DOUBLE: + case IS_STRING: + break; + default: + zend_error(E_WARNING, "Variable passed to strlen() is not a string or number"); + RETURN_LONG(-1); + break; + } convert_to_string_ex(str); RETVAL_LONG((*str)->value.str.len); } Previous Comments: ------------------------------------------------------------------------ [2004-01-14 13:24:49] scottmacvicar at ntlworld dot com Description: ------------ strlen will return a value for boolean types as well as a consitent value of 5 for an array. Reproduce code: --------------- <?php var_dump(strlen('foo')); // 3 var_dump(strlen(true)); // 1 var_dump(strlen(false)); // 0 var_dump(strlen(array('foo', 'bar'))); // 5 ?> Expected result: ---------------- string foo = int(3) bool true = int(-1) bool false = int(-1) array('foo', 'bar') = int(-1) Actual result: -------------- string foo = int(3) bool true = int(1) bool false = int(0) array('foo', 'bar') = int(5) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26906&edit=1

« previous php.bugs (#53325) next »