Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130109 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 lists.php.net (Postfix) with ESMTPS id 7410E1A00BC for ; Fri, 20 Feb 2026 16:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1771603641; bh=eeE5niRP294xHniBa/utm5vtoUM65YSl/SeYVbJfnRw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gqpuuj/GUWhnpF1kdcEGICPxhxzOfbF5Y/1Ar+BlcLIw7EvXmSUMzkvMvMImPvSi3 7jhh+O+ZeM8f2W5BLOHenIie7TLtGh7q4wlvOC4ICPq7uUglwA9e6nFcvRPsslQb1v VpmZBSgg+F6x1XDXylhtsO7SgjJRvTjfdorByoO3Lo18XOTu/k8WjPfQGGhvShyi8E iWTxagAoT9Sfn51X47bkn0AFq09cxfCffHOQraByZnkovoUJTRzXEuFL29blWhjxB5 3RncnEIuYXzT3MxNNUynntdwaui7ls09Er2U3Dw1lCbDytClxMcpzlyVcX+9jWwSWj HOqpnocDIMeBA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C49791801D9 for ; Fri, 20 Feb 2026 16:07:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (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 ; Fri, 20 Feb 2026 16:07:19 +0000 (UTC) Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-7d4c65d772cso1993120a34.1 for ; Fri, 20 Feb 2026 08:07:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771603634; cv=none; d=google.com; s=arc-20240605; b=FbTvx2ydl2aUoKdXRcpGf/81JwspKDv34WjgEYHxcYeQTEhYAPGqxyJaeF513gQq7m 1iACEJ2VkgMIYNxwvyzmR1rUZeFjPjuDPufcQOKbzsGCbd9LCnxjEiKy7Zu8urAj3yVK C8JoKjuaLwrqHO9BgB2AbmYr8gg5v6aIvzM83FKUY1uJbIQBqKo52HPhwWZCje2YaJq/ aImbvcJJzkqhIdd8UPrkbnfsAjPR9v4AD5nOHh5or2dAsFKDWoySAFgX4+5XoWcv2Jnc lZvSWoViAifzh/LR+OC/mZKxOUoo90zuSNpNQeZFMnBmW4gnnHOjA3rkHt6q/RLgVQyZ Ab2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=pI6JZNYc3qCWr9Y+Ax2lXJ/kMgakkaqq2C63FOemOJ4=; fh=0un1hNQkIQnxRVmSrptHpYePKulyS9pFxhu85Wb7djM=; b=eRnDl9uHJ0d0gWlkBad5FpToL+EKAi4tyWlDswkfD5a+TRRp4i+nNm95cU1Gw8xvwN m9YmxjBHrYLq0AnRMFx3abJ4bqdCrTqKWCBMulv2DRdSDoItnB1QCqXZgT0LpdZnSYts 6d0PzGfWBPRjEUIkpfFcycnYIuk/VDklbIzvz19a3eya/OYv9Yv9rN9FH6uUvdRVEBOA 90bpk80C8guByBiwt/IYY4AOCxG+NI7TOJatT9sGcS5RFnxtH58NlOb05wyz3cXolOcF 321ZWFdRDti5F1s0ycYOL+y0u7ARfeubrMyQoGDm45cTo2XbpmZo0yPfXRqJzc207tN7 Rirg==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771603634; x=1772208434; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pI6JZNYc3qCWr9Y+Ax2lXJ/kMgakkaqq2C63FOemOJ4=; b=ASnxJEA1z6fjQYkXY2e4EWUS0chOl7jfeMoRfdhBYRGVAHxxFzG3nelwHJdHyagV8I FNLdAsfkowu6ABpXfslCuUmbGWNUoytWDQookO9AH6ln54V3EVsy+YgA15gtyqN7s3gJ 8xRpHhY0HME66DRewjqmUUxqEmNOMVw1EjDMBhjC/HE79cNeHIJvuYoT+Ky2PiTuImgf BhSfRfxS7NFkr87NNR8bvNaGCatCLcqniD9VCD3JTh3hq1uaALGf538ZwQEdlNjf8tin p1cSM4d6KDKVjJT9Fterprzf2NnbAEKtYs8IVzcrBSlNa6GhUrpLazoCUjjy7QjO/76a yaPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771603634; x=1772208434; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pI6JZNYc3qCWr9Y+Ax2lXJ/kMgakkaqq2C63FOemOJ4=; b=i4gwSgrUWx0OK8TUksuv1jURx7HLJL+sl8LuFa8lNHj0S7lgJoAMJibyIxP63n9Oj4 SScIp/d0pJBOsEUte1pPMy+cSoNRg+dC7nGrljWvUPE3ayLrSJ2L/6iRwyosTo7kAF99 BelwT0/832++5l7RzeqUq1bPubGj4aZVdexEZOfoZMgywaF+ps90jpQLtqU+oOi5UyhW kwZEEvixkwJ5SZxfkNwszbmrKLi1kl5N6kiV4ULPMH2KKd0xHHGJwLg8H3HGJtrIXWr1 rqKrT1GRRlW5nn+RY+VdPqM0JHvxYwfWftaSNZPHMwARq3oTyw+HNxOmykh4WGrVBARJ xf2g== X-Gm-Message-State: AOJu0YwAZGGfEYHtS1a0IXrWev+rJxFI6AHp5S7A3ofAZ+IyD/WSRoyU TBYCNLiiV/jKDzG9+O+2+30oHVUe00Z14RY6fP7+rhCtG9/QUfN3tICVyRgwvbN9XkKjaL7M69c W3l7qd0kjB0hNGrMKbD+haLE2Vni5EV7AgqByIUY= X-Gm-Gg: AZuq6aKIotGzcbGP6b16gw4jHUQyXYd/dYz0MwMmeVmxQx/8KyxvzkbLGCtn55r/TTW 2imQ5clfV37Gg2+UrPENt6A265ds3lQV6jQ/1BC2+/FPhqiQeELcElveTmOhtY1/6hJb9KSLZvE LbfqoavwFewV7KLCmzw3gWHsU6p7AMkCXjoctrFwgQ2b1i5tMrkHsJsEHLC8vbE5BVuLej+09cM CV6hpFfCcSTmu5+1E7RxcFBwDeKYMwodahnN+uiV7mpVKKp7SnTV5L840Z43XGPtNJvGQS0m7el pcRdd4kEMXvLi1W7NygkkuytV0j9OYjCNF8= X-Received: by 2002:a05:6830:2a17:b0:7c7:5f09:879c with SMTP id 46e09a7af769-7d52bfbc397mr173545a34.26.1771603633827; Fri, 20 Feb 2026 08:07:13 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <1f25d77e-224b-40d6-bf19-18dfdfc9de54@rwec.co.uk> <453bc043-b4ee-423e-9561-55510f5c20a7@rwec.co.uk> <6412E222-9B0F-4139-A6F9-7D0C686197BF@rwec.co.uk> In-Reply-To: <6412E222-9B0F-4139-A6F9-7D0C686197BF@rwec.co.uk> Date: Fri, 20 Feb 2026 17:07:01 +0100 X-Gm-Features: AaiRm51zwvsTYIO1F8beh4bbJN_hHc2nIz_Zd_rNns1zvTcBRxpF4eXFCZ__T8E Message-ID: Subject: Re: [PHP-DEV] [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value. To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: mirco.babin@gmail.com (Mirco Babin) Op vr 20 feb 2026 om 08:43 schreef Rowan Tommins [IMSoP] : > > On 19 February 2026 20:24:56 GMT, Mirco Babin wrote: > > > >The Php scripting aspect makes it difficult in general > >for untyped projects to fail early. > > > This is a completely irrelevant statement. We're not talking about > failing early "in general", we're talking about a compile-time check > that PHP already makes in other contexts. Failing early is not always possible. The compiler can not always infere the correct return type. E.g. this example will succeed to compile: ```php class UnableToInfereReturnType { private function TruelyUnknown() : mixed { $a = time(); if ($a % 2 === 0) { return ['important']; } } private function ActAsVoid() : void { return $this->TruelyUnknown(); } // Lets act as if the return type is implicitly void public function __construct() // : void { return $this->ActAsVoid(); } } $it = new UnableToInfereReturnType(); // Runtime error, not a compile error. // Fatal error: A void method must not return a value in /in/MJCjX on line 15 ``` Even in a project where each and every function has a return type declaration, even all packages in the "vendor" directory have a return type declaration, there are still cases where compilation will succeed and a TypeError will be thrown at runtime. In an untyped project compilation will *always* succeed, because all return types are implicitly mixed. And the compiler can do nothing with mixed return types. In an untyped project it will always be a TypeError at runtime. Fail early is very subjective. > >I assume the spaghetti contains some version of my two theoretical > >examples. > > > >So it is safer to *not* make the return type declaration implicitly > >"void". > > > The way I see it, we have to draw the line somewhere regarding what > use of "__construct" methods is "acceptable", and what use we're going > to force users to fix. There are three options on the table: > > 1) You may return any value, the "new" operator will silently discard it [current behaviour] > 2) You must not return a value > 3) You may return a value in the definition, but > must make sure that no uses of the "new" operator > reach that return statement > > > I find option 3 unnecessarily complicated. Faced with an existing code > base, checking and fixing violations of option 2 seems a lot easier > than keeping the return values but making sure they won't error under option 3. > > I think that either we should add a simple, easily checked, rule - option 2; > or we should avoid breaking people's code, and retain option 1. Thank you for your input so far. I have decided to move forward to the official discussion phase. Kind regards, Mirco Babin