Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114650 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25264 invoked from network); 27 May 2021 17:00:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 May 2021 17:00:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C7BF21804D8 for ; Thu, 27 May 2021 10:12:33 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 27 May 2021 10:12:33 -0700 (PDT) Received: by mail-qt1-f177.google.com with SMTP id h24so717698qtm.12 for ; Thu, 27 May 2021 10:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Eo0xEG+OS4+yC6hgrkOIv9u3jtUi/+sDawtg0hi37X4=; b=jcZn+4WdJi1U6DSGn9IVhyOHBv4q18Y+zaktgBTq0Ao/UXpDdaO0wR9Ppo2wfKePLV LVAVbynzcDmFYqyqY54Cr/VDQsEODtSprlEqzMpVvcGZVrdHQswehiNK6O/madANVRWy qBZuDkHdPmngSyacuvLDnbG+fMa4/ijfvIAGTnnr7sqMMkRVTDAEHkZF5cYpQAqv91jE ZyfWj+gJFf+ftuV2lrd6bzIXkv3V5AO1YnP4oekKmcTF136bmsJpenPuAxf7mEPUwODe /QF280kNZvcbHxmrAWDW5UGq4Hu/KY7pKzPSiLJA2oZQt6OegzBiBMyyBUG7VEgMGk7e TR1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Eo0xEG+OS4+yC6hgrkOIv9u3jtUi/+sDawtg0hi37X4=; b=ElZs48UxXZ3S+SHGU3DhMz5rfhkmKP1xuPw3pwVH/54/eOhg0OGL/TyKIrWJmkHXWj TD39pCDZFy/L876CU00s5y241O0KacDHtdlLPd005u11tdgzA4vyksr7o4B2P+KZ/cfO OdyakXXayyfyf6R12VX6wdIHRtuLePeGUIzHiQUYaaOE7g7xaaHj24PDSPWzsli9wduv EbkaXR0g/ftLVBLB37qCGQHhc0TOrRZcEMbD8yaM2plMa8+dJAuiqZ6tuWOg5B6A04On 3EubK4uTi95X3MxV7SduQYiHG5zDl1LBc7czITGVOZMi0uk1Dn4fwuzlOfJ53XkdVccc BApA== X-Gm-Message-State: AOAM531/U2W3X0CqVFGYorObZp64jes8PBzUbpms7bhlgK8lRSMPiXcg fZDBhd+nqAIE5DhBzdYNNQdEJw== X-Google-Smtp-Source: ABdhPJxB5U3EKuJw2RMnSYwBsXoCEMMsbPZOAkA6tpHXj50YNnoHhJCq1ot4al3vC6s26eN4sGkrVw== X-Received: by 2002:ac8:7ef9:: with SMTP id r25mr4159874qtc.377.1622135550164; Thu, 27 May 2021 10:12:30 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id p16sm293628qtq.79.2021.05.27.10.12.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 May 2021 10:12:29 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.6\)) In-Reply-To: <8e168dd0-d937-2791-319e-10aeadb3d647@gmail.com> Date: Thu, 27 May 2021 13:12:27 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <09012BAA-3428-458A-9221-EDBB89138ECE@newclarity.net> References: <319c4288-5934-b218-d6eb-0b787a2cdef1@gmx.net> <77CC2E71-65B2-4361-A106-9E36DF4BE509@newclarity.net> <8e168dd0-d937-2791-319e-10aeadb3d647@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.6) Subject: Re: [PHP-DEV] Consensus Gathering: is_initialized From: mike@newclarity.net (Mike Schinkel) > On May 27, 2021, at 12:05 PM, Rowan Tommins = wrote: >=20 > On 27/05/2021 16:33, Mike Schinkel wrote: >> Since the argument against is_initialized() seems to almost = universally be that we should not write code that lets type properties = be uninitialized past the constructor then it would follow that PHP is = in the wrong to even allow uninitialized state past the constructor? >=20 >=20 > Yes, that is my view. The problem is that there is currently no easy = way to enforce this, because constructors are just methods that run = after the object is created, and there are a handful of ways to create = objects without calling them at all which would need to be accounted for = as well. >=20 >=20 >> If a property is defined as `?int` or `null|int` why should PHP allow = an uninitialized state to begin with? Why shouldn't PHP initialize any = of those properties to null to begin with? >>=20 >> And for non-nullable, why shouldn't PHP default `int` to 0, `string` = to `""`, `array` to `[]`, etc.? >=20 >=20 > Implicitly assigning a default from some magic list would be messy, = but requiring that the user specified one would be trivial (or would = have been, when typed properties were added): ?Foo $foo=3Dnull; int = $bar=3D0; etc >=20 > The problem is that for non-scalar, non-nullable properties, there is = no way to specify a default. One solution would have been to simply ban = such declarations (i.e. require ?Foo $foo=3Dnull rather than Foo $foo) = but that was considered too restrictive, so marking the properties = "uninitialized" is the compromise. >=20 > We're probably stuck with that compromise for now, but continuing to = treat it primarily as an error state hopefully leaves us room to do = something cleaner in future if we can work out how. So we are full circle.=20 Since we cannot guarantee that properties are not in said "error" state = it begs the question as to why developers shouldn't be able to = introspect this error state in a performant manner. -Mike=