php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52919 if does not work properly of strlen even if typecasted
Submitted: 2010-09-23 22:46 UTC Modified: 2010-09-24 05:35 UTC
From: ghazanfar dot ahmed at magsnet dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: Centos 5.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ghazanfar dot ahmed at magsnet dot net
New email:
PHP Version: OS:

 

 [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






Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-23 22:50 UTC] ghazanfar dot ahmed at magsnet dot net
Sorry, it prints "CHECK IF" where it should print "CHECK ELSE"
 [2010-09-23 23:54 UTC] felipe@php.net
This makes no sense... No way to reproduce such thing.
 [2010-09-24 03:36 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-09-24 03:36 UTC] cataphract@php.net
Expected behavior. 3 > 7 is false, hence the else block will be executed...
 [2010-09-24 04:01 UTC] cataphract@php.net
-Status: Bogus +Status: Open
 [2010-09-24 04:01 UTC] cataphract@php.net
Sorry, I didn't read the comment. Re-opened.
 [2010-09-24 05:35 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-09-24 05:35 UTC] aharvey@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 16:01:31 2024 UTC