php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75730 Stuck on is_null()
Submitted: 2017-12-25 20:45 UTC Modified: 2017-12-26 13:10 UTC
From: momchil at bojinov dot info Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.1.12 OS: Windows 10
Private report: No CVE-ID: None
 [2017-12-25 20:45 UTC] momchil at bojinov dot info
Description:
------------
Hello,

I m refactoring some old code and I hit a roadblock

if (is_null($Ticks)) { - That one gets PHP.EXE stuck consuming lots of CPU
#if ($Ticks == NULL) { - That one runs fine

I have packaged the entire solution:
bojinov.info/momchil/php/bug.zip

It contains PHP 7.1.12 x64 TS with all the needed scripts
to execute run php examples\example.basic.php

Test script:
---------------
php examples\example.basic.php

Expected result:
----------------
nothing

Actual result:
--------------
PHP hangs

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-25 20:46 UTC] momchil at bojinov dot info
forgot to mention
faulting line:
pDraw.php:770
 [2017-12-25 21:18 UTC] daverandom@php.net
-Status: Open +Status: Feedback
 [2017-12-25 21:18 UTC] daverandom@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


The two lines you show are not functionally identical.

is_null($Ticks) returns true only when $Ticks is null (it is equivalent to the $Ticks === null strict comparison), whereas $Ticks == null will return true when $Ticks is null, false, int(0), an empty string or an empty arrsy. Please debug your code, as the problem does not lie in PHP.

For more information, please check the type comparison tables here:

http://php.net/manual/en/types.comparisons.php#types.comparisions-loose
 [2017-12-25 21:45 UTC] momchil at bojinov dot info
-Status: Feedback +Status: Open
 [2017-12-25 21:45 UTC] momchil at bojinov dot info
1 question though - did you run the script on Windows 10 X64 ?

Im told a picture is worth a 1000 words
here is 1:
http://bojinov.info/momchil/PHP/Capture.png

Would you like another one where I have commented line 770 and uncommented line 771 ?
 [2017-12-25 22:44 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2017-12-25 22:44 UTC] cmb@php.net
> 1 question though - did you run the script on Windows 10 X64 ?

Have you read <https://bugs.php.net/how-to-report.php>? :)

Anyhow, from looking at the code[1] it seems that daverandom's
comment is dead on – if $Ticks' value is an empty string (for
example), the for loop in the else branch is not unlikely to be
infinite.  Please comment out the for loop and see whether that
solves *this* issue.

[1] <https://github.com/bozhinov/pChart2.0-for-PHP7/blob/f772ff8e0fc10b2e7e9c12e56637870cbcd12a27/pChart/pDraw.php#L827-L831>
 [2017-12-26 07:01 UTC] momchil at bojinov dot info
Daverandom, please accept my apologies

Thank you guys for explaining it to me .. twice

For the record, strict standards should be On by default
 [2017-12-26 10:55 UTC] cmb@php.net
-Status: Feedback +Status: Not a bug
 [2017-12-26 10:55 UTC] cmb@php.net
Thanks for the quick verification, Momchil.
 [2017-12-26 13:00 UTC] spam2 at rhsoft dot net
no, strict standards should NOT be on by default, if you decide to use a weak typed language you are responsible to read about the implications
 [2017-12-26 13:10 UTC] cmb@php.net
There is no such thing as strict standards anymore – there is
strict_types, but that would not have caught this issue.  And yes,
strict_types cannot be the default for BC reasons.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 05:01:30 2024 UTC