Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114645 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13421 invoked from network); 27 May 2021 15:21:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 May 2021 15:21:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4F77A180211 for ; Thu, 27 May 2021 08:33:13 -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_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (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 08:33:12 -0700 (PDT) Received: by mail-qv1-f42.google.com with SMTP id e8so292875qvp.7 for ; Thu, 27 May 2021 08:33:12 -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=AFcjodKhzTOyfPXFSr0mdkjvWNIdsd/mnUGF7cP1KBI=; b=R6vLgxCRpouKl5sMz+jsW+Th6iWbNPjej9LHebltsciZjQi7LW5l9KuMoGkq4Uf8Z4 UObxLG6pbBsJ2odxcztMJYaLSyoaeKL9a0IionDQ7U3NqMmq8dUgQ/Ziq9LwLzwW4twb m9NVtceyRC3NLXos47wNEczf4IiZK8yKpQD4RN6ckLFMGI+ppfHUoEM0XvDHCATjxGdt gmIEUnBNM3FnmuCgOjp+hxFLDBs2hOl6TdjF0b952BbClQI1N11rN8wLXmjVXLXbyXng x4fYc4vKLcKWt0cvnkrhSbmBmR7eze8snqMb2Us3wHSPRcKdkM/tgwm4vIXmI8zYEhCl NnDQ== 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=AFcjodKhzTOyfPXFSr0mdkjvWNIdsd/mnUGF7cP1KBI=; b=IkWFTgI31TCnXFmyKuHxFgfvf8xpATmUfA2MRyc9g51rjk0YTNcETqTJd9Gpb/Mrq6 ZO/xTds+q9kctgxO/tLodZhZy57W9HZ9cBxuyStzsM2jiSKFyXOhH8UYkdLYm36+Bffj 6miUS1PKTkzIFqrywOtpEQLbaA+fVaT90h3F1SCz+FasCz9iiNopLuP9LJ8W7au65gwB F7ruFmgUO+/ritv9k1mCfGuufcDBROWJUd1iJtnazpn/6WFngEUICbT6UKngCyWzTWU8 AYe8WDp65dBw/mYnUktz8s0rd934DoIoEBbXqhProrN0JWJfLXJpjZZyb0ZF+bOElYgG TIbg== X-Gm-Message-State: AOAM532byaNhciiHbUIUsCP/mcb4cQRMFcjMJ8vMOuPW8b2+81rAeBuf A/hmAMdsq22Zx23zQLbEzJoxtA== X-Google-Smtp-Source: ABdhPJyrNDwQFoojuopWbgQ1hF1Xg8bIjg79JRMXetmD53HjtUAfwHibkTjnGQIM+9zSZ3tD+FLpCA== X-Received: by 2002:a05:6214:d06:: with SMTP id 6mr4365260qvh.56.1622129591172; Thu, 27 May 2021 08:33:11 -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 i11sm1524966qtv.8.2021.05.27.08.33.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 May 2021 08:33:10 -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: Date: Thu, 27 May 2021 11:33:09 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <77CC2E71-65B2-4361-A106-9E36DF4BE509@newclarity.net> References: <319c4288-5934-b218-d6eb-0b787a2cdef1@gmx.net> 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 10:43 AM, Rowan Tommins = wrote: >=20 > On 27/05/2021 14:55, Andreas Leathley wrote: >>=20 >> When using isset on a non-nullable property a >> static analyzer would rightfully complain that the property is not >> nullable >=20 >=20 > Precisely, so don't mark a property as non-nullable and then leave it = unset. >=20 >=20 >> isset in this case is abused to check for uninitialized, hiding the >> actual intent >=20 >=20 > On the contrary, the uninitialized state is what is being abused. If = you want to make the intent clear, use a clear flag of "needs = lazy-loading", or whatever you're actually using this magic "not null = but not really anything else either" state for. If in fact that uninitialized state is "being abused" as asserted, maybe = the real abuse is the fact that PHP allows such a state to exist in the = first place? 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 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.? But if the answer is that PHP *should* have an uninitialized state past = the constructor then it makes good sense to have a *performant* = is_initialized() function to allow userland to discern the difference = when applicable use-cases occur. Maybe the proper solution would be for PHP to set a default value to any = uninitialized properties at the end of the constructor, null for = properties that are nullable or objects, and a known default for any = scalar types? Then post-constructor it would not be possible to have = uninitialized and thus no need for the function? -Mike