note 128337 added to language.operators.comparison
| From: | gfilippakisatsleeddotgr at main dot php dot net | Date: | Fri, 24 Mar 2023 21:50:58 +0000 |
| Subject: | note 128337 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220294@lists.php.net to get a copy of this message | ||
Please note that using the null coalescing operator to check properties on a class that has the
__get magic method (without an __isset magic method) invokes the magic method.
For example:
<?php
class A
{
public function __get($property)
{
echo 'Called __get for ' . $property . PHP_EOL;
}
}
$a = new A();
echo 'Trying null coalescing operator' . PHP_EOL;
$b = $a->test ?? 5;
echo 'Trying isset()' . PHP_EOL;
if (isset($a->test)) {
$b = $a->test;
} else {
$b = 5;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 2a02:587:2214:1600:d0c6:f788:9bc1:559f)
----
Manual Page -- https://php.net/manual/en/language.operators.comparison.php
Edit -- https://main.php.net/note/edit/128337
Del: integrated -- https://main.php.net/note/delete/128337/integrated
Del: useless -- https://main.php.net/note/delete/128337/useless
Del: bad code -- https://main.php.net/note/delete/128337/bad+code
Del: spam -- https://main.php.net/note/delete/128337/spam
Del: non-english -- https://main.php.net/note/delete/128337/non-english
Del: in docs -- https://main.php.net/note/delete/128337/in+docs
Del: other reasons-- https://main.php.net/note/delete/128337
Reject -- https://main.php.net/note/reject/128337
Search -- https://main.php.net/manage/user-notes.php