Bug #75980 [Com]: greater or equal (formerly >=) is missinterpreted

From: Date: Mon, 19 Feb 2018 13:17:04 +0000
Subject: Bug #75980 [Com]: greater or equal (formerly >=) is missinterpreted
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214031@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75980&edit=1 ID: 75980 Comment by: rolf at rolfjentsch dot de Reported by: rolf at rolfjentsch dot de Summary: greater or equal (formerly >=) is missinterpreted Status: Open Type: Bug Package: Scripting Engine problem Operating System: windows 10 xamp PHP Version: 7.2.2 Block user comment: N Private report: N New Comment: well to make it a final the problem only arrises when i start my php section with <?. it does not occur when i start it with <?php Previous Comments: ------------------------------------------------------------------------ [2018-02-19 13:11:06] spam2 at rhsoft dot net so what is now with your wrong statement that >= finish interpreting? > But a if(strpos($_SERVER['SERVER_ADDR'],"192.168.10") !< 0) > still does what it does in previous versions frankly i have no idea why one would write this code and what it is supposed to do! strpos() either returns a integer which can be anything including 0 where 0 is the pretty clear fact "haystack starts with needle" in case needle don't exist in the string it returns a boolean false which is ducmented behavior for decades - so the only correct code tests if the result is a boolean false and this MUST be done with !== or === depending on the logic you implement compare return values which can be 0 or boolean in weak mode is and always was wrong - that's it - when your code for comparison is not strict PHP needs to implicit cast *one* of both values to the type of the other which makes a 0 to false or false to 0 depending on the order and so the result is just by luck that's it - that didn't change and completly off-topic assertions like >= stops interpreting making such bugreports even more worse - there is no bug, your expectations are just wrong and with reading the documentation you would not have written >= to start with http://php.net/manual/en/function.strpos.php Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. ------------------------------------------------------------------------ [2018-02-19 13:01:35] rolf at rolfjentsch dot de Thank you for your hint with - if(strpos($_SERVER['SERVER_ADDR'],"192.168.10") >= 0) + if(strpos($_SERVER['SERVER_ADDR'],"192.168.10") !== false) But a if(strpos($_SERVER['SERVER_ADDR'],"192.168.10") !< 0) still does what it does in previous versions Wbr Rolf Jentsch ------------------------------------------------------------------------ [2018-02-19 13:00:44] spam2 at rhsoft dot net > made it possible to have a <? ?> or <?php ?> anywhere in the source document frankly you mix completly different topics to start with <? ?> aka short-open-tags should not be used for many years <?=?> got an exception indepdendent if short-open is allowed in config > a normal if statement with a ">=" compare opertor finishes interpreting php THIS IS NOT TRUE - PERIOD - otherwise the sample with you broken code won't reach the echo statement at all and when you replace ">= 0" with a proper !== false it even works as intended [harry@srv-rhsoft:/downloads]$ php test.php http://qnap/piwik/ [harry@srv-rhsoft:/downloads]$ cat test.php <?php $_SERVER['SERVER_ADDR'] = '192.168.196.0'; if (isset($_SERVER['SERVER_ADDR'])) { if (strpos($_SERVER['SERVER_ADDR'],"192.168.10") >= 0) { $where="http://qnap/piwik/"; } else { $where="https://someurlhere/"; } } else $where="https://someurlhere/"; echo $where, "\n"; ------------------------------------------------------------------------ [2018-02-19 12:54:59] rolf at rolfjentsch dot de Formerly versions of php (like 5.6) made it possible to have a <? ?> or <?php ?> anywhere in the source document. Now with php 7 (actually tested on 7.2.2) a normal if statement with a ">=" compare opertor finishes interpreting php. (As it would be expected when i had written "?>" ) On top - dont know if related to the above a function defined inside the <html> <body> tag is not recognized as defined. aamof i defined a function there definetly before its first usage and it does not work. moving it before the <html> <body> tag solves the problem ------------------------------------------------------------------------ [2018-02-19 12:43:53] spam2 at rhsoft dot net it would be a good start to write proper code and then it even works >= 0 when comparing the boolean 'false' triggers implict type-casting and false weak >compared to 0 is the same as int 0 when the string starts with needle that this worked in some arbitary PHP version was just by luck - if(strpos($_SERVER['SERVER_ADDR'],"192.168.10") >= 0) + if(strpos($_SERVER['SERVER_ADDR'],"192.168.10") !== false) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=75980 -- Edit this bug report at https://bugs.php.net/bug.php?id=75980&edit=1

« previous php.bugs (#214031) next »