ID:               26906
 Updated by:       [EMAIL PROTECTED]
 Reported By:      scottmacvicar at ntlworld dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: All
 PHP Version:      4CVS-2004-01-14 (stable)
 New Comment:

As PHP is a typeless language, this behaviour is expected. Please take
a look at this extended version of your script:

var_dump((string)'foo', strlen('foo')); // 3
var_dump((string)true, strlen(true)); // 1
var_dump((string)false, strlen(false)); // 0
var_dump((string)array('foo', 'bar'), strlen(array('foo', 'bar'))); //
5



Previous Comments:
------------------------------------------------------------------------

[2004-01-14 13:25:53] scottmacvicar at ntlworld dot com

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);
 }

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

[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

Reply via email to