|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-09-23 22:46 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
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.