On 5/26/16, 12:48 PM, "Fleshgrinder" <[email protected]> wrote:
>>
>> Under another 5th option, the problem you state does not arise. Disallow
>> "public int $x;". Under this option you may declare $x with type int and
>> an initial value or you may declare $x without type but you may not
>> declare $x with type (nullable or not) and undefined initial value.
>>
>> Tom
>>
>
>This would be a valid approach too, yes. I personally would be against
>it because I do not want to initialize all my properties.
>
> class A {
>
> private int $x;
>
> public function getX() {
> if (empty($this->x)) {
> $this->x = 42;
> }
> return $this->x;
> }
>
> }
>
>This would not yield an E_NOTICE because both isset() and empty() never
>do. This allows the attentive programmers to keep up there coding
>practices without the necessity to assign meaningless values everywhere.
>
> class A {
>
> /** -1 is invalid */
> public int $x = -1;
>
> /** 'INVALID' is invalid but empty string is allowed */
> public string $s = 'INVALID';
>
> /** Null byte is invalid but anything else is valid */
> public string $welcome_to_the_c_world = '\0';
>
> }
If you want that kind of thing, you can do it the old PHP way like this
class A {
private ?int $x = null;
...
Tom
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php