Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114646 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16593 invoked from network); 27 May 2021 15:54:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 May 2021 15:54:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C80B1804E3 for ; Thu, 27 May 2021 09:05:48 -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-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 09:05:47 -0700 (PDT) Received: by mail-wr1-f50.google.com with SMTP id x7so382009wrt.12 for ; Thu, 27 May 2021 09:05:47 -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=ccOgwTn4EDacl/H+WpTX3OShz17JVy2z11Tz2YAVryU=; b=eKtwdo38I2ettdnQxqPDg1mjzNx8A1+kxuK4RcVvyVsPTv6ThEFl7dD+XZ3v5UzjDV Hv/WeNPzC388Ww2TJEU058AzmtXqM2KDyzFYZ/JAg2T0krck2Qj7Lou+4u/74IYsIXwT T7U7hVmxqxQ8/WAWP2FkBzntuwAAByuI2n6Nnmx9JwKJwrcTU9u76mHrzw2YLwsYC+Un LMJgaZ1SN/Xgs3qn1oFEdjO3t1XO3GTykhm6BO3iFEwyOYHUzVacAUvWzzQ2jYK4XLX2 evi7wy2Jt/oHyPKMbnjR+I53EdtYNDyhJNG2volY0WFnNq2g1qiWUoGN6nnzAktbmsuw DR8g== 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=ccOgwTn4EDacl/H+WpTX3OShz17JVy2z11Tz2YAVryU=; b=OGXHFQCrpJa0o9YC3ZcHjsRD49S17GTJhT6biqG+C6r4JEUDgFMKIe/XLqjsuwgsWv gDBo0gjYsqO6G3/Xuc6HTiW1h783AN5GlNSoj+mijZz6OKjJcTP/bBW6K+iQ65Sh7BJC ZsiaZhpERnN2COJ5WhDA7fblpi68KbJ3u4oWWGJWdBnuxcqpWl5kHVi7KFPjpQeD8edH nASg3cPxxDbxffCS6A7dXV0NIiTjBAinlQsZ1VaXZleqSjXTvY/hsfLD9JAeIwBBtMRf FDdRXGRrNELOK+Iqya01rw0nzN6+Gso6d7zeqDT3Jfx40zOva5mH0XUljaU0LnvW774O Q42g== X-Gm-Message-State: AOAM5307jFw/kMFx/O0Pnb5gAM0l/d6cUWpwgUZlJsHxbZ0DlA0QPUWg 7Oj86CCEEq79iL2AhxKpmnBf+SKixaQ= X-Google-Smtp-Source: ABdhPJzua6RKArYMhPGi1Em4qjNR0F6Z+FqXzYC+PeMak+znvsysEvbPVAY/IyJSKTGSxa9A6a2Izg== X-Received: by 2002:adf:cd06:: with SMTP id w6mr4101022wrm.399.1622131545095; Thu, 27 May 2021 09:05:45 -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 k11sm11215149wmj.1.2021.05.27.09.05.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 May 2021 09:05:44 -0700 (PDT) To: internals@lists.php.net References: <319c4288-5934-b218-d6eb-0b787a2cdef1@gmx.net> <77CC2E71-65B2-4361-A106-9E36DF4BE509@newclarity.net> Message-ID: <8e168dd0-d937-2791-319e-10aeadb3d647@gmail.com> Date: Thu, 27 May 2021 17:05:43 +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: <77CC2E71-65B2-4361-A106-9E36DF4BE509@newclarity.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 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? 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. > 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? > > And for non-nullable, why shouldn't PHP default `int` to 0, `string` to `""`, `array` to `[]`, etc.? 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=null; int $bar=0; etc 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=null rather than Foo $foo) but that was considered too restrictive, so marking the properties "uninitialized" is the compromise. 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. Regards, -- Rowan Tommins [IMSoP]