Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93523 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20399 invoked from network); 25 May 2016 18:06:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 May 2016 18:06:06 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.219 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.219 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.219] ([81.169.146.219:63979] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/38-14311-B89E5475 for ; Wed, 25 May 2016 14:06:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1464199561; l=7907; s=domk; d=kelunik.com; h=Content-Type:Cc:To:From:Subject:Date:References:In-Reply-To: MIME-Version; bh=cxiKARhTlgefiZAmM32h6PSNopi79A/R9a7V50k1/C0=; b=mBO2gfyrVtCsQUGcz6hwmGr3Sq+2jA2UH/q6/OO0/LBr4mlOzz2h4tyEE47nMalJjx4 zr0BivXzzBTOWnYFSWtPxJ5dAL8QDNbhTbXBkP1k2VeMV9ChVQywUoHe7PbOWKx4cv4Jh pzzOed8XscXAENCz3Wv3qD+7UgVvphTj9HQ= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtO3E6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f42.google.com ([74.125.82.42]) by smtp.strato.de (RZmta 37.27 AUTH) with ESMTPSA id 6070b5s4PI60qQi (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Wed, 25 May 2016 20:06:00 +0200 (CEST) Received: by mail-wm0-f42.google.com with SMTP id n129so195162619wmn.1 for ; Wed, 25 May 2016 11:06:00 -0700 (PDT) X-Gm-Message-State: ALyK8tLQGjttqUURSJn8uNddL1I8Co67186FK1UA0JIr12xttOrWVwuq/+vYYzewMNmbDFHBF7eBDPHiNxkQXA== MIME-Version: 1.0 X-Received: by 10.28.91.209 with SMTP id p200mr4942204wmb.19.1464199560829; Wed, 25 May 2016 11:06:00 -0700 (PDT) Received: by 10.28.53.132 with HTTP; Wed, 25 May 2016 11:06:00 -0700 (PDT) In-Reply-To: References: <7B.12.14311.F79C5475@pb1.pair.com> Date: Wed, 25 May 2016 20:06:00 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Bob Weinand Cc: Andrea Faulds , PHP Internals Content-Type: multipart/alternative; boundary=001a11443ad8b42f130533ae864e Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: me@kelunik.com (Niklas Keller) --001a11443ad8b42f130533ae864e Content-Type: text/plain; charset=UTF-8 > > Hey Niklas, > > > Am 25.05.2016 um 18:21 schrieb Niklas Keller : > > > >> > >> Hi Niklas, > >> > >> Niklas Keller wrote: > >> > >>> > >>> I disagree here. Properties are always null by default. The current > patch > >>> disallows > >>> access to uninitialized variables only if they're not nullable, since > null > >>> isn't a valid value then. > >>> > >>> I don't think having to explicitly set them to null is the think we > want. > >>> And it's not what I'd expect given the current system. > >>> > >> > >> PHP's existing untyped properties are implicitly initialised to null, > and > >> so yes, we would essentially only be copying our existing behaviour. > >> > >> However, I think it is worth asking whether our existing behaviour is > >> useful before we preserve it here. From my perspective, it is unhelpful > >> that PHP does not warn you about using properties you haven't > initialised, > >> and this applies to both typed and untyped properties. In some cases > (like > >> in my linked list example in a previous email), null might be a > meaningful > >> value and worth distinguishing from a property not having being > initialised > >> yet. > >> > > > > Null shouldn't have any meaning apart from "not set". It should never be > a > > meaningful value. > > > > > >> We can't change the behaviour of our existing untyped properties (or at > >> least, that's beyond the scope of this RFC), but we could choose the > >> behaviour we find more useful for our typed properties. > >> > >> Consider that we did something like this for parameters. Not providing > an > >> untyped parameter gives an E_WARNING: > >> > >> $ php -r 'function foo($a) {} foo();' > >> PHP Warning: Missing argument 1 for foo(), called in Command line code > on > >> line 1 and defined in Command line code on line 1 > >> > >> But not providing a typed parameter gives a TypeError: > >> > >> $ php -r 'function foo(int $a) {} foo();' > >> PHP Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be > >> of the type integer, none given, called in Command line code on line 1 > and > >> defined in Command line code:1 > >> Stack trace: > >> #0 Command line code(1): foo() > >> #1 {main} > >> thrown in Command line code on line 1 > >> > >> So there's a precedent for applying stricter rules when type > declarations > >> are used. > >> > >> Thanks! > >> > >> > >> -- > >> Andrea Faulds > >> https://ajf.me/ > > There is a difference between not set and no meaningful value. > > The former is literally unset(), the latter is null. The only semantics > PHP exposes here is that not set can be upgraded to "no meaningful" value > in form of null with a notice. > > The difference thus is quite minor, but semantically important. > Hence to *set* the value, we need to explicitly set null. > Adding a type shouldn't alter behavior, so setting it explicitly to null shouldn't be required. Regards, Niklas > If we don't do it this way, we won't have a way to explicitly *set* > nullable properties to a value (null in this case). (without explicit unset > in ctor). > > Bob --001a11443ad8b42f130533ae864e--