Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130021 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 97F071A00BD for ; Thu, 5 Feb 2026 17:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1770313273; bh=qKYUgxMhODursYzrypFnj0PUyExIB4wWYBE/8nOE1vs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RI2AjgIQN9nvW7LS6Abw6gcuHn15mxQUY/d/aFnVH8G9qTpYAb0HvZIRVy/uK1/ar lmaEdo9TAsIuaCgidZq+CppTw3XBRepujrk8Drqj9BhBvrtpZWlKHlq9tOlvQJHmlj Zjj62xnvNed7f+5LlqWpiZ4Ta8cVRdMh9SE+y0VZAmrEQhx6OShj2OfWUMHbi92wqc q2yBdcAYVIg2I9OqelQhkI0hWh1GAdw8mPmuB2v/aZgJR3COS/XyaEL5O2qMGM5lvZ 9o0h+yyXo3afPA4EGCRm92Nkg84LCZ1jAQ91nvF0mU8EZyWajgOU66EJ6Ky1x1RfuD 8anchHinJSbtg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 591EF180088 for ; Thu, 5 Feb 2026 17:41:11 +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-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 ; Thu, 5 Feb 2026 17:41:04 +0000 (UTC) Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-7d1890f7cefso1073440a34.3 for ; Thu, 05 Feb 2026 09:40:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770313259; cv=none; d=google.com; s=arc-20240605; b=Yxmc4L/Xw1ZJUxdN7zT7KiLx97AOdoGrnKpvbTgjFNCIKyUt178DwocokOtX86Rjbt m7G+Sw3evyCkdrH0JY6sq0/uPjBLPvVPuB7fCsABHPIiHivBMutU3975b7g99SrV6Yi2 V/WsKPEWvtQNPkLfJ0+VstDTpvy78qv3XlJioA/BphkCnAuCP6OuLsHKmSM2OBLbsVey AoBX2ypDwaAt4gS+mbBjswrFDCfkbgoy13eEiqNhOM102c6BXE4eeGxKJXNbRcX+BfJ+ AuHIKsWrJU2BXZspVGuBWV+93Zzp7h2nrL0AizlsVVMonMML5Gpa9p56Dc4KdU2ehii3 29DQ== 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=6heTxoMIpprf2W/LJ5iPsovJc7OLnZqeBzB9UZQABwM=; fh=4tytjhG5+ySp4dS8TT3glIm8x63aEeiUDfnQqxW22lk=; b=QNK3O1YVTT2KHkUkVnJAps18dLtSSm2FhnhKJCpDerPVReYrcJVPd02fCLRf5Su1qV /EEvbulLkG/9iC+WGMDcuPf4T8RsFp4Hoh80RN5Io1frxuQcu4sm+jpha9BK2IZbPlZG kbGYB3HTrxFa5VhfJGD0cpQMUlW+B/opaMGgz2i0LMu3vp2emzFwRSIi3XZsr3YLhP7+ NDxTwfdQ51y5k4Hc1F5qFlmW9IZqfUr6p+qryue3/STVQs4nGN2EIp/AJBUlGNpsshHt NC1kKgH0zjYzm+SGK/8r57LgMQunW8u4DOH0j2qnmnWbaVuRoCP0T86DsQNAs2ezIwJG DC9g==; 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=1770313259; x=1770918059; 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=6heTxoMIpprf2W/LJ5iPsovJc7OLnZqeBzB9UZQABwM=; b=LvyPtw40n2sDuma9w+R12haTy81peSApsdL7fBbwFAEMjXDkAJTstO2e23o5AGpVWX 8w1jT2fm+9L7c3Lb5jtXlrSth4s+OMIvpZVo89380lJ3qlkx8WM0pFYKejBCIesjf+Fn FjTT2pRtWxP0GktrrPcnDaohMjgE1kq1aRRCukx9hdSjFHmU2rYlZB37TgKqzmH+bQJP tEVjFxYEgmmsu6HXc4E8vOTPSi/D2Afs1jB6eAyOUOd9rH0j4gjKwgzouWXAPHM++7Vn bLVNhsSdPs9gBzL2/wITVXrZ2O7PdyV3NRjEtMZ3P4/WQZRUCRzsrNYxdYfzYAmxrwjF M1gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770313259; x=1770918059; 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=6heTxoMIpprf2W/LJ5iPsovJc7OLnZqeBzB9UZQABwM=; b=aYhDQjKduwh+6qYyNaRNbkeduYsmUDFndnXojw3fD3trlvZql9wyjBXqgCOIIIoWVu kwW1EduZo+aCWrEVGLvhi1CH8cln5PyoIjdcri/IUXZH82QdQRQoYavZOjg1EY/NTULe cL5pC+edp9X16LR/Sqw7jZczcfK3mEGxKuJ660ACQELAhZbrJZkVigA2DcMWl4n7Hvvg juw4JOmXajYekKtgKoDtIPWjvnecEwF2r5fEUAxxmfcOdildArSo1DvfG1JZtuJ6GvHv hfvZ3oo0d65ILG2rOlD7uCp58g/Q5uctCtadsBkVgZuWDOCx+EalCWKCzO/XVFW9/ESg sPiw== X-Gm-Message-State: AOJu0Yy6ywXkMCEyXN7ei/cci6TVX5b8tbJ5XUtomiWDzrLSR6uHaHQi canso57ZNH31cndaiK+lqn6JSJy6b5uJJaVDhEKegG6pV6x4rqoPbwlRxPoXX9ZWHP2rEZuqNpV LRzvnWl69n2r4KsORTJIB9lgyjpVwcHU= X-Gm-Gg: AZuq6aKw7gJUi4BD3ZJjUk2SwpQxFFmAMjv6puMlS3jrpO2ziMbKM7wSqY2L97OAOzc Hm4rC4NZ09DAvmyesTiFflYw5QRgwWr4KgP0OTEoVxhN9DtN8CDmqxTB+c9g2xYdW4MM4O1zy27 K6iErowESrawU1xpPJWYEZum2TaFssoQJNoPMm+l7cUB8h0+J8Xc6Jas+CLkWJ+lU5v/eEuhZDy nct5HHRPs2vw0RruwVrB+m1s/HLZsWkRMBa7gysdyB/10X7Si0uA1NoP/m2Tb7qMvMM25+Jdo+H Uzn9wKY0TiDV91YQubrdI40= X-Received: by 2002:a05:6830:6302:b0:7d1:8b51:c88c with SMTP id 46e09a7af769-7d448b058a0mr5474828a34.38.1770313258826; Thu, 05 Feb 2026 09:40:58 -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: Thu, 5 Feb 2026 18:40:46 +0100 X-Gm-Features: AZwV_Qjgp7rVGcNc3unthEvdosdAHGKPC_Q6li1-AXVtjP0DX23jaP2vj7n2tR8 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) >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. I can't share real code, because this project is not open source. The project I maintain uses constructor middleware as follows: ```php // Laravel 9 class MyController extends Controller { public function __construct() { $this->middleware(function ($request, $next) { if (!Security::isLoggedIn()) { return redirect()->route('login'); } return $next($request); }); } } ``` The goal is to redirect guests to the login page. To prevent unauthorized actions from being performed. In Laravel 9, MyController was instantiated before any middleware was executed. When __construct was executed, Laravel was still initializing, not much could be done in the __construct function. Hence the middleware solution. Then came Laravel 12 and constructor middleware was removed. Also, middleware is now executed before the controller is instantiated. And here's where I made my mistake. I removed the $this->middleware() call, and changed this to: ```php // Laravel 12 - my mistake, this it totally wrong! class MyController { public function __construct() { if (!Security::isLoggedIn()) { return redirect()->route('login'); } // Because the return value is pointless, no redirection // did find place. // The unauthorized user could actually call real controller // functions, which could be anything from showHomepage() to // rebootTheSystem() - exaggerated of course. // // But PHP did not warn me, did not error, did not speak up, // did nothing to inform me of my mistake. } public function showHomepage(Request $request) { } public function rebootTheSystem(Request $request) { } } ``` >So, to restate your proposal: you want to disallow returning from >constructors=E2=80=A6but only if invoked when using the `new` keyword? That is correct. >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? That is correct. >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? Deprecation sounds like a good step forward. Kind regards, Mirco Babin