Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130080 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 7EA5E1A00BC for ; Tue, 17 Feb 2026 07:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1771313996; bh=8C2QHshlmtlpj87FWMBDqtsvGT+GkskpsY0ALCtHgfE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=M21oDgHhJE4fCXPKNeVohExQcDGv9FrzjwJ78snESMd6u7paZMRCN1MnOsN0T3b5n uPd9TKg/vU4QpVd+meynkBQXm+noyrduKzSuhK5QEhu7IGjM02W4KUq+mvhGvxuY4Z t2qhPcn/kB+A2tIqX33JQkMms0SKoZifgbqbpNVkUY8QagjhEZHNenTWxZZrpK1N/m a6EUzSRLHSfOvaaw8E3pZmGePjEG4hxGk4jRVDqvttlMMWuWikYk/ZWWTwUQhfCLik bPAUf47VqfZa0KTTMG2U1y31E32KKZlDcxerm99zzuP8CMkZjIoZcu/lUkuLwzqI8i UHx4yp8WvMOng== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 60865180077 for ; Tue, 17 Feb 2026 07:39:55 +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-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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, 17 Feb 2026 07:39:55 +0000 (UTC) Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-7d196a2334fso3108619a34.1 for ; Mon, 16 Feb 2026 23:39:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771313989; cv=none; d=google.com; s=arc-20240605; b=AdGP5zYdACshd7UTAPob6591isj3xgEjwiWSqLZeB8oBR6QoiaqbRKCTkNZ3LZRRBC 6Lk5a2gwX9lqU1yDXC10NmD0UFsdhA64tM7vpNNlS6RvzgZdOCKde/zVQTr0IVRgjCMG 4exc3v3bTF6QzUElbOH+j27S+ALpiFpPGt3q0XvcBVncNjvL14i0fsROoiH6+PRbqJsJ WhlDfQLRwHZujae5u7d1pedj9YI+ApzS2Z1kKcucZO2g23ddVr7xKj3HPY1oL1YPhIa/ a70hodskFdPMmelpmlMGJFYKwVqnA1Bkq6YTYbPjfCXQNGwkNQDnbbDNUuygkSvyQEmQ Nurg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8C2QHshlmtlpj87FWMBDqtsvGT+GkskpsY0ALCtHgfE=; fh=4tytjhG5+ySp4dS8TT3glIm8x63aEeiUDfnQqxW22lk=; b=Tp/eOwowDmypJ50yIRTQ9EwIrSnRFAMlIy96TxBTgjl0yJh7aUZOUBi08ZEevw/OLq b6UKR8qh8CB0mGOycxzwOnv1h59D3pzK1lHe7ucCuPqd+4I5InOnubz3oRgeLYZ35bLQ d6wkWT75dR/ieoaHa8ND2rd4GhibwMHZd5+p4Leb/HJaTxZeQNlquiXopyQhFFMBT22M NQusGqLt68WDAQgSCILNiWQLDPOFF7H9i3dCs6K3tClD53s6xYNoNwIAiyXr4vdW8Ln2 viH3x8iWD6UVXNkS+nDgIO5mazJbcibA2BdF+Wsg8UvySwFXz9RQFiv8K37n//5TMYqh ei+w==; 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=1771313989; x=1771918789; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8C2QHshlmtlpj87FWMBDqtsvGT+GkskpsY0ALCtHgfE=; b=moixfBne6VRTRsD6cW4W3x/mT2XCSdD1grImP+ejWpyFOcL2RzdWG8YnGhBA+hhLVa 714/I3IrjcF351dNGOTbBasuTLLle0iM9q+h/8Bxob834eZtgeSDiKmSHgRqpVOwUDv5 E2LGVeuBPzMoUUsRYWEEjryrtJBCKdWbYdnhkbqd74NOy6JBQP9omfL+UNcdj1Xj87G6 ABPkIoYegTLncerABKR86B2XBHkNuBETFAJPTkD+5LAa+sSN7yBhkg4ALT4rxyhAdlfA ddzWAtZVLfqS5uALE9hPkEnHGJXIAXp7VWepgZW9vV1ddo1VhkDNE4jHDrCp0XOPKOLf 0WbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771313989; x=1771918789; h=content-transfer-encoding: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=8C2QHshlmtlpj87FWMBDqtsvGT+GkskpsY0ALCtHgfE=; b=BbiVAHkXRnH2v2JHGBQZS8vOE1x0lh1pgiL3xrGmm3tMCUCjOCScOopecBO65P/K2+ 642mXrQgRZXY9YT7rK5pQcOUmkv9Dqso43xi55OveHyUY8JG8BZM5HrNzpH82u7rBSMg VWGHw7BcdCx9LRVlwNcdHGNr4jf0YiisGMSK5loHNc2OLgMBZUefBqYWhIDBvQJnAveD jATvCHd1pv+oTyYt0ZO3fQy4zLA6S39+6GU1feF/Z1RTmb8I7NhuImPAy4elECdBGhLe P3CcnuFrbBcS0JafhwRKlCqJGmZ3M7i8b3LbUTyyRavFaHy8eho3VLlCPc5pTs9EKH29 g7Pg== X-Gm-Message-State: AOJu0Yy0AEmzqu5EgXPf+KjK97ohVxnjHFIKGKVUKv3KehV1SkscC1DQ /Aa8vyCBwW37+Dl1nmsP4+yFQ1hwhbVkzOGKPZbaw/VKhTJivRxnipm9fq8BOdL3FeJueceBgTL EdOaZ9uxoI8Eqky8nyBjIcTLbiLBMpKT14wiEky8= X-Gm-Gg: AZuq6aIXQwzPtzanZpN9HDlPI3RpJuEIuP2Z3orXHBvkxA0i/L2nekFRZ2+Jyz3Wk4D IATAeU0qkKoXPMevj5Pj/3CfDTbMWsQVdJ9n8tz1KcrEYZ7bvqeVzz2HGlAzc6MdxreD3F/wJdM /FvIh4wE4yQb9A1c83GpOEjT2PAlwSKDVBf9dvmsOivjCQCkuGRtx6tVR42bWiSd8pcVIIONqa8 jFU+waSeWEDk/PV381UHVG4rVCWz33K9tBWII0aMmCLdLu+TD/kHACuycmtEqNqsEtPaicS+sKK YukvAhPWebOrxtoWMwgvzupzceeHXDSabpH3 X-Received: by 2002:a05:6830:1291:b0:7ce:5139:301b with SMTP id 46e09a7af769-7d4cde48389mr4929316a34.8.1771313989464; Mon, 16 Feb 2026 23:39:49 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <20260204022858.DA5F81A00BD@lists.php.net> In-Reply-To: <20260204022858.DA5F81A00BD@lists.php.net> Date: Tue, 17 Feb 2026 08:39:37 +0100 X-Gm-Features: AaiRm525WhqdmdCl3mYDchff0lcDeFZwVTMQ2t502kZwor6wJp-PmaljnQ30X8A Message-ID: Subject: Re: [PHP-DEV] [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value. To: Ben Ramsey Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: mirco.babin@gmail.com (Mirco Babin) >The "Make constructors and destructors return void" RFC was voted on and >declined in 2020. PHP has come a long way since then, and I'm curious >whether a similar proposal (targeting PHP 9) might pass nowadays. I'd >certainly consider voting for it. Perhaps in PHP 8.6, we could begin >emitting a deprecation message for constructors that return values? As written to Tim D=C3=BCsterhus: I have prepared a RFC at https://gist.github.com/MircoBabin/aaa574297c8d1baa879f19c99ce28e93 Kind regards, Mirco Babin Op wo 4 feb 2026 om 03:30 schreef Ben Ramsey : > > On 2/2/26 12:00, Mirco Babin wrote: > > # Problem > > > > The "new" operator internally calls the __construct() function. However= , > > the return value of the __construct() function is silently lost. This i= s > > very error-prone; I personally made a major security mistake with this = when > > upgrading from Laravel 9 to Laravel 12. > > Can you elaborate on this? I'd like to better understand what the > problem was with constructors that returned values when you upgraded > from Laravel 9 to Laravel 12. > > > To prevent future problems, my proposal is to have the "new" operator > > explicitly issue warnings, and later have it explicitly abort when the > > __construct() function returns a value. > > So, to restate your proposal: you want to disallow returning from > constructors=E2=80=A6but only if invoked when using the `new` keyword? > > So, if you call `$object->__construct()`, there's no error, and you can > get the return value, but if you do `new Foo()`, you'd get an error? > > > And I've been told that the > > rejected PHP RFC Make constructors and destructors return void > > ( https://wiki.php.net/rfc/make_ctor_ret_void ) rejects my proposal. > > However, my proposal is explicitly about the "new" operator and not > > about return types. It does, however, concern return values. > I'm not sure how this differs from the void return type proposal. When > it throws a TypeError, it will effectively be saying, "this method can't > return anything," which means the return type is `void`. > > The "Make constructors and destructors return void" RFC was voted on and > declined in 2020. PHP has come a long way since then, and I'm curious > whether a similar proposal (targeting PHP 9) might pass nowadays. I'd > certainly consider voting for it. Perhaps in PHP 8.6, we could begin > emitting a deprecation message for constructors that return values? > > Cheers, > Ben >