#26292 [Opn->Bgs]: substr returns "0" for any offset on the string "0"

From: Date: Mon, 17 Nov 2003 22:54:06 +0000
Subject: #26292 [Opn->Bgs]: substr returns "0" for any offset on the string "0"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-50516@lists.php.net to get a copy of this message
 ID:               26292
 Updated by:       sniper@php.net
 Reported By:      ravacholp at hotmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Strings related
 Operating System: windows 2000
 PHP Version:      4.3.2
 New Comment:

With a more reliable test script:

# cat t.php 
<?php
$str = "0";
var_dump(substr($str, 0, 1));
var_dump(substr($str, 1, 1));
var_dump(substr($str, 5, 1));
?>

# php t.php 
string(1) "0"
bool(false)
bool(false)

No bug here.



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

[2003-11-17 17:16:07] ravacholp at hotmail dot com

Description:
------------
substr() returns "0" for any offset on the string "0" using the length
1.

This causes an infinite loop if you are checking for leading zeros in
your string using substr().

Reproduce code:
---------------
$str = "0";

print (substr($str, 0, 1) == "0");
print (substr($str, 1, 1) == "0");

print (substr($str, 5, 1) == "0");

// only the first line should evaluate to true

Expected result:
----------------
111



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


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


Thread (2 messages)

« previous php.bugs (#50516) next »