On 5/26/2016 1:41 PM, Lester Caine wrote:
>> var_dump(property_exists($g, 'x')); // true
>
> or array_key_exists('x', $g) in our consistent style but as has been
> pointed out we do not have a simple 'exists' ...
> $g->exists('x') ?
> along with $g->isinit('x')
>
I like the exists() idea. :) But we might not need it.
On 5/26/2016 1:41 PM, Lester Caine wrote:
>> var_dump($g->x); // null + E_NOTICE Uninitialized
>> 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
>
> Unless null IS the required initial value? Why should we have to
> initialize a nullable typed property explicitly?
>
You don't have to unless null *is* the required initial value.
You are only punished with an E_NOTICE if you try to access a property
that was never initialized with anything. This would be 100% consistent
with old PHP behavior.
$x;
var_dump($x); // null + E_NOTICE Undefined
$y = null;
var_dump($y); // null
class O {
public $x;
public $y = null;
}
$o = new O;
var_dump($o->x); // null + E_NOTICE Undefined / Uninitialized
var_dump($o->y); // null
Only the E_NOTICE for $o->x would be new.
On 5/26/2016 1:41 PM, Lester Caine wrote:
> I'm still stuck in the simple model of things where 'x' is expandable so
> we have the simple generic variable of old (PHP4 days) which now has
> additional attributes such as accessibility (public etc) and a few
> special cases of type filtering but is lacking a tidy way of adding the
> more useful filtering attributes such as constraints and yes typing.
>
> properties and associative arrays are simply managed list of these
> simple variables so why do we need different functions to access them.
> Within a class isset($x) should mirror isset($this->x) and exists($x)
> makes sense along with other 'object' related functions, but is there no
> way to get back to a lot simpler consistent handling of variables ...
> and a more constructive way to add flexible type constraints.
>
With this proposal we would not go anywhere else. We would make it more
consistent and allow the typed properties RFC to continue. Unless I
missed something in the discussion or got something wrong again. Please
correct me!
--
Richard "Fleshgrinder" Fussenegger
signature.asc
Description: OpenPGP digital signature
