rfc:null-propagation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:null-propagation [2018/01/23 10:13] – daverandom | rfc:null-propagation [2018/01/29 16:33] (current) – Move introduction to Introduction. The code style change was made to preserve vertical spacing, not because I care about the brace placement holy-war. levim | ||
---|---|---|---|
Line 6: | Line 6: | ||
* First Published at: https:// | * First Published at: https:// | ||
- | ===== Proposal | + | ===== Introduction |
A common requirement in object-oriented programming is the need to check whether an object is '' | A common requirement in object-oriented programming is the need to check whether an object is '' | ||
Line 12: | Line 12: | ||
<code php> | <code php> | ||
- | class Foo | + | class Foo { |
- | { | + | |
private $bar; | private $bar; | ||
| | ||
- | public function __construct(? | + | public function __construct(? |
- | | + | |
$this-> | $this-> | ||
} | } | ||
| | ||
- | public function getBar(): ?Bar | + | public function getBar(): ?Bar { |
- | | + | |
return $this-> | return $this-> | ||
} | } | ||
Line 28: | Line 25: | ||
| | ||
$foo = new Foo(null); | $foo = new Foo(null); | ||
- | |||
$bar = $foo-> | $bar = $foo-> | ||
Line 39: | Line 35: | ||
</ | </ | ||
- | This proposal | + | ===== Proposal ===== |
+ | |||
+ | This proposal | ||
<code php> | <code php> | ||
Line 46: | Line 44: | ||
var_dump($result); | var_dump($result); | ||
</ | </ | ||
+ | |||
+ | This operator does not suppress any errors that are generated by the left hand side of the expression, it only short-circuits the right hand side. | ||
===== Examples in other languages ===== | ===== Examples in other languages ===== | ||
- | * [[https:// | + | * [[https:// |
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// |
rfc/null-propagation.1516702400.txt.gz · Last modified: 2018/01/23 10:13 by daverandom