Re: __isset() and null value

From: Date: Sat, 05 Sep 2020 20:44:01 +0000
Subject: Re: __isset() and null value
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-111848@lists.php.net to get a copy of this message
Hi Michael, On 4 September 2020 18:03:29 BST, "Michael Voříšek - ČVUT FEL" <vorismi3@fel.cvut.cz> wrote: >Ideally, we should introduce __exist() which should return true even if >value is null Magic methods in PHP allow the user to overload some built-in operator or behaviour, so it doesn't make sense to talk about a new magic method in terms of how users are expected to implement it without first describing what built-in functionality it overloads. Is the idea that $foo->__exists($bar) would be called when running property_exists($foo, $bar)? If so I suspect most cases would be clearer if they used some context-specific interface with a well-named method. For instance: interface SomeORM\DynamicDBModel { public function hasColumn($columnName): bool; } A notable difference from __isset is that you can write isset($foo->bar) without having 'bar' as a string value, which AFAIK is not possible with "exists". Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#111848) next »