Re: [RFC Proposal] Null Coalesce Equal Operator
| From: | Midori Koçak | Date: | Tue, 12 Apr 2016 15:36:16 +0000 |
| Subject: | Re: [RFC Proposal] Null Coalesce Equal Operator | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92230@lists.php.net to get a copy of this message | ||
what is sugar?
On Monday, 11 April 2016, S.A.N <ua.san.alex@gmail.com> wrote:
> Maybe even more sugar? :)
>
> <?php
>
> class SugarCache
> {
> // Methode getValueFromDB() called, if its value null
> public $value ??= $this->getValueFromDB();
>
> // Methode getValueFromDB() called, if $value not transmitted or null
> value
> public function __construct($value ??= $this->getValueFromDB())
> {
> //...
> }
>
> public function getFromCache()
> {
> // Methode getValueFromDB() called, once upon init static $value
> static $value ??= $this->getValueFromDB();
>
> return $value;
> }
> }
>