Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123376 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 80F8D1A009C for ; Tue, 21 May 2024 00:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716252065; bh=DVJiFFosu1IVrSwwlRDPyDo1w1RjHzPodIhunyC2AbY=; h=References:In-Reply-To:From:Date:Subject:To:From; b=YrG3X1uzvyigpha+wqU24fJKIjyDhjUpSPrWTHSuMQoAq3jRp1qLW7vj+QC//Iz6H E6pJPG/11Pw3z4tPPRM7EPMVhb61mHboM1LabFNZX4YKeNPVqgBMVz5f0q8hTgJyMu qBs6xVO0+JZL/pH/wDKGHJRyVAkZBoNQvQX4hxISUpQoMrKpC1SEzhcnHxM3a7JksI VWb2GAsUbFm30woMGBXiTXcOFn8CdzFbk4wEJe2YdhyrdyvYfitcHELssxWMSnXa1T OcbrvcAPV9jvy4SRCo+LjCD43ToV2WldEUxLM85CgcGsZSOg1pqd0g8nFzaA6K12Ty dCvDoXVVmnTjg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1E79618006E for ; Tue, 21 May 2024 00:41:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 21 May 2024 00:41:04 +0000 (UTC) Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-69b514d3cf4so34787726d6.0 for ; Mon, 20 May 2024 17:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716252008; x=1716856808; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DVJiFFosu1IVrSwwlRDPyDo1w1RjHzPodIhunyC2AbY=; b=J8JrdCQoGBxAEUZY+gvpKWW2cZhjZyOrQQucBsZDOZUH3K0xR4kKrwAPNoiwAGkq1l p6e3FfkTJkJIzPTFQlvXk1GWGKGmbQl0KjG/o3HmyFfi0ztcQleEYnLikA8n660TGnnP NILoaK/EYGvdS9Pd1UtzynMwPGi++P7/FXv0V5tB7GBUxp6v3VxvLFe6Ywli7H/tX4Mg 72Cepvo+19CfgWIP1QEYOMDmaBcwrkU5/0HoQO0Hj4rF9Z+OgbptiRKd4JGu5Msgjlhh DpzDUhH9WyRZp/WSCtzChiqr/Q9atmmqfkJrLmZbvMu9293y8XDLEsP9n9PrVdBD+oj8 LKkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716252008; x=1716856808; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DVJiFFosu1IVrSwwlRDPyDo1w1RjHzPodIhunyC2AbY=; b=A+NkzABhXGhr5jSSwr14zJSgpvhDwhDh4SY5UV6yIRKHEtG9MShL58K7aOv1nxFlex Tr0k3ydZsgda3taCSLTmP9KkbiQWoYUWfDXXhAOFYnFxeyinQCzH58h7fzbd+4HYwJwo gOGi9zz2jO/DCcuG78yqOtrhfhKlojmo0zY9evGBrNKzfNOGsHxtOSeAd/KYQedvwecU cXiXY+BBbSzc4VoTeKXahyDlO1xTuenRmFnlPgBRDiyPJSbo9bLvLfaZp0nm5ua//EJ6 RvfQ03gN0cIF+TiF1v5la3eXdEaJ0R1+bJKEaJlWNVOJNLn4vQI6U0oaSZGYKKrTnm2g NFlg== X-Gm-Message-State: AOJu0Ywev3oMFcPC26dKLkmOYIFlCaE1G048BonmHUtIUYuwZJZCc1cU QbUSffD6+iIIikmiIggICSC01sJGTD/uljOAo/r0El3WvWDiVVVyVmLMYZy7ekly22qtFmnK9uj ylKPTcnrDpMcTJkJDPc9b5PCNnC0ZNlZfTi2uoQ== X-Google-Smtp-Source: AGHT+IHQ4u9rkvnciye6J8VUNRSeqyrcQPqU5GQUQkZLxb44zLLgraiKFiu6BdyjxekxnK9uS/BcRMmVwIMLdoZIVqA= X-Received: by 2002:a05:6214:4806:b0:6ab:7270:fcbe with SMTP id 6a1803df08f44-6ab727102b5mr6882606d6.58.1716252008242; Mon, 20 May 2024 17:40:08 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <878c09ca-860e-4c0c-85ae-2cd0246cda3c@rwec.co.uk> In-Reply-To: <878c09ca-860e-4c0c-85ae-2cd0246cda3c@rwec.co.uk> Date: Tue, 21 May 2024 02:39:56 +0200 Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] Checking uninitialized class properties To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) On Sat, May 18, 2024 at 4:41=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On 18/05/2024 11:52, Luigi Cardamone wrote: > > Are there any downsides in adding a > > specific syntax to check if a property > > is initialized with any value? > > In my opinion - and I stress that others may not share this opinion - > the entire concept of "uninitialized properties" is a wart on the > language, which we should be doing our best to eliminate, not adding > more features around it. I fully agree. The reason NULL was deemed the "billion-dollar mistake" is not because NULL isn't a useful value, it's because it is implicitly part of types that are commonly never NULL. For example, in C, there's no way through the type system to convey whether a pointer returned from a function may or may not be NULL (ignoring hints through attributes). As such, the user must look at documentation (which may be inaccurate), or even guess whether NULL must be handled. A failure to do so will not result in any compilation errors, but crashes at runtime. Luckily, PHP does not suffer from this issue. null is only allowed when the type says so. However, if you leave your class properties uninitialized, you're essentially recreating this issue. How do you know whether it is safe to access class properties? May they be uninitialized under certain conditions? The type system has no way of conveying this information. There's no way to know, without looking at the implementation. Static analysis won't be able to catch it for you either. So, as Rowan suggested, it is better to hint at this "uninitialized" value that must be handled through the type system, currently most conveniently through single-case enums and union types. Ilija