php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74152 if statement says true to a null variable
Submitted: 2017-02-22 21:34 UTC Modified: -
From: kontakt at markus-kottlaender dot de Assigned:
Status: Closed Package: Apache2 related
PHP Version: Irrelevant OS: Linux Mint 18
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kontakt at markus-kottlaender dot de
New email:
PHP Version: OS:

 

 [2017-02-22 21:34 UTC] kontakt at markus-kottlaender dot de
Description:
------------
I have a php file containing exaclty the code below.
It prints true when run in the browser but false when run on command line.
I cleared my browser cache, hit ctrl+f5... I even changed the scripts file name.
After making changes to this simple file (just adding whitespaces to the end) and hitting f5 in the browser it says false _once_ but than true again.

PHP 7.0.13 and 7.0.15
Apache/2.4.18

Related question on Stackoverflow:
http://stackoverflow.com/questions/41970037/if-statement-says-true-to-a-null-variable

See the last comment: "I've verified that both the cli and Apache both use the same version and the output varies between both of them. I am out of idea's, except an update of the PHP version if its available. [...]" – Xorifelse

I let him see it in action via team viewer and he verified that I'm not talking shit.


Output of apt list --installed | grep php:

libapache2-mod-php/xenial,xenial,now 1:7.0+35ubuntu6 all  [installiert]
libapache2-mod-php7.0/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php/xenial,xenial,now 1:7.0+35ubuntu6 all  [installiert]
php-cli-prompt/xenial,xenial,now 1.0.1+dfsg-1build1 all  [Installiert,automatisch]
php-common/xenial,xenial,now 1:35ubuntu6 all  [Installiert,automatisch]
php-composer-semver/xenial,xenial,now 1.2.0-1build1 all  [Installiert,automatisch]
php-composer-spdx-licenses/xenial,xenial,now 1.1.2-1build1 all  [Installiert,automatisch]
php-gd/xenial,xenial,now 1:7.0+35ubuntu6 all  [installiert]
php-gettext/xenial,xenial,now 1.0.11-2build1 all  [Installiert,automatisch]
php-intl/xenial,xenial,now 1:7.0+35ubuntu6 all  [installiert]
php-json-schema/xenial,xenial,now 1.6.1-1build1 all  [Installiert,automatisch]
php-mbstring/xenial,xenial,now 1:7.0+35ubuntu6 all  [Installiert,automatisch]
php-mysql/xenial,xenial,now 1:7.0+35ubuntu6 all  [installiert]
php-pear/xenial,xenial,now 1:1.10.1+submodules+notgz-6 all  [Installiert,automatisch]
php-phpseclib/xenial,xenial,now 2.0.1-1build1 all  [Installiert,automatisch]
php-symfony-console/xenial,xenial,now 2.7.10-0ubuntu2 all  [Installiert,automatisch]
php-symfony-filesystem/xenial,xenial,now 2.7.10-0ubuntu2 all  [Installiert,automatisch]
php-symfony-finder/xenial,xenial,now 2.7.10-0ubuntu2 all  [Installiert,automatisch]
php-symfony-process/xenial,xenial,now 2.7.10-0ubuntu2 all  [Installiert,automatisch]
php-xml/xenial,xenial,now 1:7.0+35ubuntu6 all  [Installiert,automatisch]
php7.0/xenial-updates,xenial-updates,now 7.0.15-0ubuntu0.16.04.1 all  [installiert]
php7.0-cli/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-common/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [Installiert,automatisch]
php7.0-fpm/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-gd/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-intl/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-json/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-mbstring/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-mysql/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-opcache/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-readline/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
php7.0-xml/xenial-updates,now 7.0.15-0ubuntu0.16.04.1 amd64  [installiert]
phpmyadmin/xenial-updates,xenial-updates,now 4:4.5.4.1-2ubuntu2 all  [installiert]

Test script:
---------------
<?php

$foo = 'foo';

$bar = null;

switch ($foo) {
    default:
    case 'foo':
        if ($bar) {
            echo 'true';
        } else {
            echo 'false';
        }
}

Expected result:
----------------
false

Actual result:
--------------
true in browser, false on command line

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-23 04:48 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=330a7b62c3558aa987ee80e12f1914347d3a9eee
Log: Fixed bug #74152 (if statement says true to a null variable)
 [2017-02-23 04:48 UTC] laruence@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC