Skip to content

Instantly share code, notes, and snippets.

@Philoreiser
Last active May 20, 2021 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Philoreiser/8842edfe56da99bd4d8799b8f5a53349 to your computer and use it in GitHub Desktop.
Save Philoreiser/8842edfe56da99bd4d8799b8f5a53349 to your computer and use it in GitHub Desktop.
DO NOT compare a "string" value with a number
<?php
$val = '';
echo ($val < 0) ? 1 : 0;
<?php
$val = '';
echo ($val == 0) ? 1 : 0;

PHP 7.2 與 8.0 兩種版本環境執行結果是不同的,應避免發生直接 空字串0 (number) 比大小的可能。不同「型別」(概念上) 的兩個值做比較都要當心。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment