Re: [RFC][Vote] Typed Properties
| From: | Fleshgrinder | Date: | Thu, 26 May 2016 10:49:24 +0000 |
| Subject: | Re: [RFC][Vote] Typed Properties | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93558@lists.php.net to get a copy of this message | ||
On 5/26/2016 12:39 PM, Rowan Collins wrote:
> On 26/05/2016 11:16, Fleshgrinder wrote:
>> $o = (object) ['x' => null];
>> var_dump(isset($a->x)); // false
>> var_dump(property_exists($a, 'x')); // true
>
> Apart from a typo in your example (you change from $o to $a), this is
> already the current behaviour, and always has been:
> https://3v4l.org/NeqGl
>
> isset() is really very simple: if the thing your accessing would give
> you the value null, it returns false, otherwise it returns true.
>
> Regards,
Now I feel stupid but I guess I got lost myself. :P
This means it is even simpler, we just have to add the E_NOTICE and be
done with it.
$g = new class { public $x; };
var_dump($g->x); // null + E_NOTICE Uninitialized
var_dump(isset($g->x)); // false
var_dump(property_exists($g, 'x')); // true
var_dump(is_null($g->x)); // true + E_NOTICE Uninitialized
var_dump($g->x == null); // true + E_NOTICE Uninitialized
var_dump($g->x === null); // true + E_NOTICE Uninitialized
This behavior would be true for all variations:
class A {
var $x;
public $x;
public int $x;
public ?int $x;
}
No notice for the following:
class A {
var $x = null;
public $x = null;
public int $x = 0;
public ?int $x = null;
}
--
Richard "Fleshgrinder" Fussenegger
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc