php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5772 if ("" == "0") inconsistent behavior on IIS 4.0
Submitted: 2000-07-25 00:34 UTC Modified: 2000-07-25 11:58 UTC
From: steve at teamits dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0.1pl2 OS: Windows NT 4.0 SP6a
Private report: No CVE-ID: None
 [2000-07-25 00:34 UTC] steve at teamits dot com
If I use the following line on a UNIX server (running PHP 3.0.9), the test works as intended...meaning if "</body" is the first entry on the line, the test returns true.  I am 99.9% sure I have the exact same line on my test machine running PWS 4.0 (I can't check from here).

if (strpos(strtolower($line), '</body') == "0") {

However, on IIS 4.0, if $line is a value that does not start with "</body", the test still returns true...I'm assuming this is because strpos() returns "" (false, which it does) and the parser compares that to "0" and assumes "0" is false, therefore the test "if (false=false)" returns a true value.  I can get around this by changing the test to

if (strpos(strtolower('a'.$line), '</body') > 1) {

...but it seems to me that the function/parser should work the same under PWS and IIS and UNIX.  I was just confused why my page worked on the UNIX server and wouldn't work under IIS.  BTW, I have tried both the CGI and ISAPI versions, and both behave the same way.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-25 00:43 UTC] joey@php.net
The CGI on both win32 and Unix returns the same for me using this test.
Instead of this workaround you have invented, why not use:

if (strpos(strtolower($line), '</body') !== FALSE) {

(Which I'd venture a guess is already being used, in one form or another,
on the Unix box)

Double check and make sure that the Unix and the NT box really are using
the same code, and one is not using === ( or a variant thereof )
 [2000-07-25 09:59 UTC] stas@php.net
Please read manual for strpos. You shouldn't compare strpos return value to 0.
 [2000-07-25 11:58 UTC] hholzgra@php.net
this is one of the small differences between 
php 3 and 4

see 
http://php.net/version4/incompatibilities.php
third topic from bottom 

in php 4 you will have to compare strpos result
with "=== 0" for "begibbing of string match"
or with "=== false" for "no match found"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 01:01:30 2024 UTC