3 ms·
PHP 8.0 Is Released
- rhabarba 6y agoPros: - Introducing Rust’s null-safe operator. Cons: - Still having null as a possible value.
- coldtea 6y agoNot exactly Rust's, lots of languages have something similar...
- rhabarba 6y agoI found some Rust similarities in PHP 8’s new features (match, #[] annotations, ...), so this fits in somehow.
- zRedShift 6y agoIn Rust ? is the try/error propagation operator. It converts the error to the correct type, if necessary, and returns it. let ok = return_result()?; and let ok = match return_result() { Ok(ok) => ok, Err(err) => return Err(err.into()), }; are equivalent In 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);