note 128966 added to language.operators.precedence
| From: | php at richardneill dot org | Date: | Wed, 18 Oct 2023 02:40:58 +0000 |
| Subject: | note 128966 added to language.operators.precedence | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220924@lists.php.net to get a copy of this message | ||
PHP and SQL have different approaches to null-handling.
In PHP, arithmetic operations on null treat it as zero:
<?php
echo 5 + null; //5
echo 5 * null; //0
$x = null;
$x++;
echo $x; //1
?>
whereas in SQL, most operations, where any parameter is null, are null:
5 + null; //null
5 * null; //null
Nulls in strings are sometimes converted to '' and sometimes errors:
<?php
echo "hello" . null . "there"; //"hellothere"
echo strlen(null); //used to be 0, now causes error.
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 82.8.243.31)
----
Manual Page -- https://php.net/manual/en/language.operators.precedence.php
Edit -- https://main.php.net/note/edit/128966
Del: integrated -- https://main.php.net/note/delete/128966/integrated
Del: useless -- https://main.php.net/note/delete/128966/useless
Del: bad code -- https://main.php.net/note/delete/128966/bad+code
Del: spam -- https://main.php.net/note/delete/128966/spam
Del: non-english -- https://main.php.net/note/delete/128966/non-english
Del: in docs -- https://main.php.net/note/delete/128966/in+docs
Del: other reasons-- https://main.php.net/note/delete/128966
Reject -- https://main.php.net/note/reject/128966
Search -- https://main.php.net/manage/user-notes.php