-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 1.17.0
-
Component/s: None
-
None
When dealing with a class that implements the __get and __isset magic methods, the null coalesce operator will generally not invoke __get if __isset already returns false: https://3v4l.org/GBCfS.
However, the BSON Document and PackedArray classes behave differently, in that using the coalesce operator still results in an exception:
$document = MongoDB\BSON\Document::fromPHP([]);
var_dump(isset($document->foo));
var_dump($document->foo ?? 'fallback');
This code outputs the following:
bool(false) Fatal error: Uncaught MongoDB\Driver\Exception\RuntimeException: Could not find key "foo" in BSON document in /Users/alcaeus/Code/mongodb/mongo-php-driver/tests/bson/bson-document-property-access-002.php:8
For consistency, the read_property and read_dimension handlers should not throw when the coalesce operator is used.