Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114651 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27339 invoked from network); 27 May 2021 17:12:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 May 2021 17:12:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E4B24180211 for ; Thu, 27 May 2021 10:23:53 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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:23:52 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id g17so598913wrs.13 for ; Thu, 27 May 2021 10:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=ZW/4lh9YE/6i/rSWaVh5yz9cZn2AG6QpeR7z98wECCY=; b=rqg5MpV6FNuKUq3YFJMPtTcT78NUgm++wbbqlHJHDv35FhlhE+lElSHmfxVXXCXcWO Zjk0kXnzN2pZCKgHQQ3PHVX9CYQIZeXOevQtzUoU7VI4AjnHeMJPhrhv4OiET5I7s97o AnNBuIYfjdIQh+r9k5Tb0961eHDamlEGT2r2ZPcwr+cXUAwOdNwdSxw9BilEouxEGHbP IcX6o8XlpXk4VKIaxeLMDfHyGd5eEg82diXu/QNS+hdNahP1O8cWB5KNzixi1HHf2fnY 5IOPn9UVub5wuBtNdrM/2LCKCxaRusKtMChL2Q7fzPL9ASnS8PZghmECBLey6t0hh9HG LoOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ZW/4lh9YE/6i/rSWaVh5yz9cZn2AG6QpeR7z98wECCY=; b=NoxxavSPnXX5/KX9hne1cH3ppUS58sC/yCg8MXPww76P76hzxlX4e6KUCYf/8WKU/9 bKhxBai3fGk7ruoSK3hDXAM7ds3xskD4beOT1ozAi78nkbeW3kCRoewVee+cYbPVXwz8 pDC5zHACMTI4XQQ0bqYJxG8VvtEMMODj2ZJlc9yuO21RTlNjSORY7bLdTrftYUkLtzoM Up8IhdPlY31fITL/XCCG2wMx3+nQXjhCgLRYxPvOrO7QSVWrOy52pW4FDrsl666+lo6E rmoLGi7EiRZbOxrC+e4rjuPxGlc71gf9yT/9FN0zZNoH4DPEt9R5mgWVhDI/EugI4njM IsRA== X-Gm-Message-State: AOAM531XusPjPV9STt1m8JN7ZnjcIGQACa7Ya8fhMSyNmHVqPK0nLAM5 rJIG7yHLlPPszPBosQR/EjB2bC/ULCU= X-Google-Smtp-Source: ABdhPJxe4vbx6wcb3z+GFtUKYUXJqbOMMjcqUSshKq/vcF+X7JmeYmC8cLKVn7XykBAY0fdRimvd1g== X-Received: by 2002:a5d:4843:: with SMTP id n3mr4445611wrs.411.1622136229970; Thu, 27 May 2021 10:23:49 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id b10sm4183702wrt.24.2021.05.27.10.23.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 May 2021 10:23:49 -0700 (PDT) To: internals@lists.php.net References: <319c4288-5934-b218-d6eb-0b787a2cdef1@gmx.net> <0ef9c29d-942f-15a1-27d4-89155ec81a90@gmx.net> Message-ID: <535c8837-eceb-93b4-416c-fff3a1bb35dd@gmail.com> Date: Thu, 27 May 2021 18:23:48 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <0ef9c29d-942f-15a1-27d4-89155ec81a90@gmx.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] Consensus Gathering: is_initialized From: rowan.collins@gmail.com (Rowan Tommins) On 27/05/2021 17:13, Andreas Leathley wrote: > > How is "uninitialized" magic? It is a state of a class property in PHP > that is currently being exposed via reflection Apologies if my last message was a bit too hastily written, and may have come across as rude. What I meant by it being "magic" is that it can't be represented by any value or type. A lot of the examples in this thread attempt to use "uninitialized" like it was an extra value for the variable, as though the type of the property was "int|null|uninitialized". But that can't be declared in the property's type, and I don't know if there's even a docblock convention for "note that this property might be deliberately uninitialized, when it is, that means this ...". Since we now have union types, you can actually be a lot more explicit about the extra state, and use something like "int|false|null"; in 8.1, you'll also be able to use "int|SomeEnum|null". Since those are real types, with real values, no extra functions need to be added to the language, and everything feels a lot less "magic". > I have seen quite a > few places where it occurs - for example with setter injection in > frameworks, as an alternative to setting a property in the constructor. Just to reiterate, the new function would *only* be useful if you were trying to distinguish the uninitialized state from a null value. If you have a property which you *know* might not be provided, you already have "null" to represent that. For instance, a property that might hold an instance of LoggerInterface, but only if the user calls a setLogger method, can be declared as "?LoggerInterface $logger=null", and tested with "isset($this->logger)". PS: A much sillier reason why I hate "uninitialized" is that I consistently misspell it as "unitialized" :P -- Rowan Tommins [IMSoP]