Bug #52919 [Opn->Bgs]: if does not work properly of strlen even if typecasted
| From: | aharvey@php.net | Date: | Fri, 24 Sep 2010 03:35:57 +0000 |
| Subject: | Bug #52919 [Opn->Bgs]: if does not work properly of strlen even if typecasted | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-154607@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52919&edit=1
ID: 52919
Updated by: aharvey@php.net
Reported by: ghazanfar dot ahmed at magsnet dot net
Summary: if does not work properly of strlen even if
typecasted
-Status: Open
+Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Centos 5.5
PHP Version: Irrelevant
Block user comment: N
New Comment:
Works for me; as Felipe says, there doesn't seem to be a way to
reproduce this. The sample code prints "CHECK ELSE" on every install I
have to hand, which is exactly what I'd expect, given strlen("700") is
fairly obviously 3.
I'd suggest double checking that all your values in your actual code are
actually what you think they are and following up with a user support
channel such as an appropriate mailing list, IRC, or Stack Overflow.
Previous Comments:
------------------------------------------------------------------------
[2010-09-24 04:01:02] cataphract@php.net
Sorry, I didn't read the comment. Re-opened.
------------------------------------------------------------------------
[2010-09-24 03:36:23] cataphract@php.net
Expected behavior. 3 > 7 is false, hence the else block will be
executed...
------------------------------------------------------------------------
[2010-09-23 23:54:27] felipe@php.net
This makes no sense... No way to reproduce such thing.
------------------------------------------------------------------------
[2010-09-23 22:50:34] ghazanfar dot ahmed at magsnet dot net
Sorry, it prints "CHECK IF" where it should print "CHECK ELSE"
------------------------------------------------------------------------
[2010-09-23 22:46:23] ghazanfar dot ahmed at magsnet dot net
Description:
------------
IF does not produce correct result when strlen is used to calculate
length of a
string which is an integer
Test script:
---------------
//IF does not seem to evaluate properly
$row['number'] = 700; //in my case if was value retrieved from mysql
// force typecasting
$number = (string)$row['number'];
if(strlen(trim($number)) > 7) {
print "CHECK IF"; }
else {
print "CHECK ELSE";
}
//It will always print "CHECK ELSE" where strlen($number)=3 (computes
correctly)
// where 3 > 7 is false
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52919&edit=1