PHP 8.0 Is Released
php.net
php.net
- Introducing Rust’s null-safe operator.
Cons:
- Still having null as a possible value.
let ok = return_result()?;
and let ok = match return_result() {
Ok(ok) => ok,
Err(err) => return Err(err.into()),
};
are equivalentIn TypeScript/Kotlin/C#/PHP and many more languages, ?./?[]/?-> is the null conditional operator. Rust doesn't have it in operator form (? works on Option<_> types as if they were a degenerate Result<_, ()> type). instead, you "flatmap" the Options with and_then() (if it's fallible) and map() if it's infallible. Or just use bare pattern matching.
$country = $session?->user?->getAddress()?->country;
is let country = session
.and_then(|session| session.user)
.and_then(|user| user.get_address())
.map(|address| address.country);