Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115498 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27826 invoked from network); 19 Jul 2021 14:44:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jul 2021 14:44:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7D71C1804C8 for ; Mon, 19 Jul 2021 08:09:34 -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-vs1-f54.google.com (mail-vs1-f54.google.com [209.85.217.54]) (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 ; Mon, 19 Jul 2021 08:09:33 -0700 (PDT) Received: by mail-vs1-f54.google.com with SMTP id r25so9574030vsk.2 for ; Mon, 19 Jul 2021 08:09:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9xxTp2Hdk7PHTZN7F/mx46VcirCsTHnHOoIsaAYUtEk=; b=L5jLcwxBBpneaPnJnh+OB0A9wuxUONSKvKRi6SEhCtanFF96tOiAJJULfYmqfxvEDp 186/+RXZNWP1c0hvOg12K8Ir7Hy452tHl5wtFgXX3BbfsZeP7VGx5l/NOnNGBdoEfN7A V331MRQ9HlL5QGU15yg9lYXsCvBVcQqwRE22LrAgAv17LJCuxWLde0OYVB4qECqgGagm 93FIbAhaL/69KiU876HTI2WHBS+gnMEPcUQTqmByF7i74q4InU+WcL+S3n1n5ScNA+bZ zhDdNN0pEQn9xHLhDwWXx9AgpwjMsBgvtxnsodsXTTSybvaVha09PxH7g64c309Gd7Rb 7l3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9xxTp2Hdk7PHTZN7F/mx46VcirCsTHnHOoIsaAYUtEk=; b=aX7BGJoBPyWea6oDdOwmiwT9RbDuBpcOpCL5/LtURVf/xmdEHrDC+mNgfveZjI0T2T XmdvZ9gW611gMB2m533C8gAOnqPoVWPK2cV65QeIV/Y7rbiJpXP45m/qM0S0UHDam34k ibyKffZd0tEA90lW21KPN+zPKw+BDxn4ZQymUnO/MCKaxyZQy9mXFpmaqLz3PyRqqxj9 oc3QPTWmlfP0lTCYwNM2OQGC3ymsy8uRpy8XZM/GA4+oQoQcmqj+pWnm40sXa+j1t08X b6CiIS8M9h2YfT7d/CQU6YhLV9opI8GvPfSQAeo4o/3EGQXmCZeZB20/OFQjpjSCLggp kxRw== X-Gm-Message-State: AOAM531aMUrcSuPJ7cwUW9SsQ1Q12/Ex5x4ktrhlQty8yr5pIuHJxxjL n4rFFFJH9TeUXjETsb5nRThdSvVUJRdFKLKBkA752g== X-Google-Smtp-Source: ABdhPJxxJpj8VmA6SL6WsP3LhBeQKYkJ/7gI2uTW0eWT6H+0hX1mTej17A73CBz872mHS55y1SiqSYbOZ3lBMTNbwNM= X-Received: by 2002:a05:6102:2131:: with SMTP id f17mr23781360vsg.1.1626707368291; Mon, 19 Jul 2021 08:09:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 19 Jul 2021 16:09:17 +0100 Message-ID: To: Nicolas Grekas Cc: Guilliam Xavier , PHP Internals List Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] intersection types and null for defaults, properties and return types From: Danack@basereality.com (Dan Ackroyd) nicolas-grekas wrote on the PR: > ?X&Y cannot be confused with It confused me. A compiler might understand it, but as a human I have trouble understanding it. Trowski wrote: > The syntax should be either ?(X&Y) or (X&Y)|null Non-ambiguous syntax is much better than ambiguous syntax. On Mon, 19 Jul 2021 at 15:26, Nicolas Grekas wrote: > I don't know the future, and nobody does. Maybe not, but we can look at the past and make predictions. Allowing null when then parameter type does not include null is supported in function parameters for legacy reasons: ``` class Bar{} function foo(Bar $bar = null) {} // parameter has implicit nullability. ``` But it was deliberately excluded from typed-properties: ``` class Bar{} class Foo { private Bar $bar = null; } PHP Fatal error: Default value for property of type Bar may not be null. Use the nullable type ?Bar to allow null default value in .... ``` Instead, you are required to be explicit on the type declaration: class Foo { private ?Bar $bar = null; } Prediction number 1: At some point implicit type nullability of function parameters will be deprecated. People should consider changing any code they have from implicit declaration to explicit. e.g. change: function foo(Bar $bar = null) {} to function foo(?Bar $bar) {} Prediction number 2: Having a null type in the language will happen before PHP 9, which will enable people to have many bike-shedding discussions over ?Bar vs Bar|null. But this discussion is moot for 8.1. This limitation might make intersection types not be considered usable by some projects, but the feature freeze is today. cheers Dan Ack