Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129108 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 EEED11A00BC for ; Thu, 6 Nov 2025 05:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762405323; bh=SDgBlW4L3cvwNo0Cd++00qgE1eCb4gNDJJ3J0O92zys=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GHjzfA+z6PRJN+wogdFIx6mbnh/9/chOMoNjdWgUwNLDmzjb9ryNjjT0dsLKzrDv+ 8n25sGooMIWybuPor/ExFytMZP5Q3xzz+xVN+1Gk/YRDzesnSepoh8Pl+LU6xSBvT1 2mHULgpxFrpQLVqe99kFalsbbCVSEOqq8GfzoZowXmia4xWI8FvmQui8Pe5KbDuwDe wlMCzPcCUjLpGNJQ3PTSzI0kE+k4yQwmaiZbraJXuaQQEMe/E/DGLXLZ55SnrnDpNG bTqlLY3TjFj97zDrXHnKGDJ/kjfrU/X6YrAbFiodWjk/ZzH2Csz2Av4i5a7913EWAM 9jusurUcs8VRw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D0C88180072 for ; Thu, 6 Nov 2025 05:02:02 +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=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 autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) (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, 6 Nov 2025 05:02:02 +0000 (UTC) Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-54aa30f4093so193617e0c.3 for ; Wed, 05 Nov 2025 21:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762405317; x=1763010117; 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=zTEXnFtDR0VMzwKB5MsDaZ5BzfF6y5goMJCNx+oa+DI=; b=Paumskog1Nq69CKoqqndh/GAdebEioGVr3a0Nzt1SJJYWpFt/QEETKbpSfVb+Q4jj3 G5oI/UzBOJeTFwoSFjZ3JmiBAHdVj0kHipz9sgKM0pA/dpnh+bI6dgrIQVfNRgCI94C4 KEiADsxCi8F/ev28PG1rk1LJIrD7BZ56Bisxdfp54E4HJWfupzaAM9bbr74VoVsjEdYQ xD3uwhFKZsuP8In/YvmbzCnzyMLTCIVYWXqn9AXoxyeplmNuluPVzp9hGaOclAOvtWuO TWgYJUvG6rAcSHHkzaNYzRWw2drj8o7/NYTDfRXAGIjvcOldyJcC1PN/1JwhZdqAamkL jrZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762405317; x=1763010117; h=content-transfer-encoding:cc: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=zTEXnFtDR0VMzwKB5MsDaZ5BzfF6y5goMJCNx+oa+DI=; b=GHhrCLpRkoqjD9qEtiDGN/fu0F2IMMqyvz7djeCHvqkg2RJAg7p0Dh7Yzhv4syKXsa 07OaQsuYUx4JmIgcGxkeFIIeYep7RMlt8NNKWFUGU61wLck57DFCrkL15h4dqnERQXo6 IzF6Ig6QGtWwwcbA4ZLo18fOGkKecH0x2BpsiuJA+5uqHGkkG0/24SpumkMtZNnMN+Jq HrrlsC6nK0ttBpUav3BjUOP83YZGtM+Nmhm4EyJKxsU/0fBvC8HlmAn7EoxXXzL2jUPM VU/YyIhJXpSkqRvm8Xaj+sgbkwNw2Ybddi3iVHtz+pRs3LEohg+6lw7tVCS9nKH0mpU7 fw2g== X-Gm-Message-State: AOJu0YznIBDDL8Rc6bz3hOQj8S3sKyWHnvefpwZ1S6Hau8FRzT/rLlza tD6QNlLCQbFeWMHlJ1H547TF8Ol30A/DUpRS7dT8F8k4yEs/JMZnIV0966qudUyBD+H9CvmvZ1J CJIJyFo7CnRrHUOeNgeVGTlB7RIZfkbOnVusGns8= X-Gm-Gg: ASbGncuKJWHwNcfkKCqHwYCAGc8m/hfO/StMrV9KHqNw9jmwgKmd7o9Iy23gMN+P5Nt /c3m20uDq/eXuDnPGX+W4cGtucH+FtyrGDyAxylxHilO6pcyXVXoTZ/lBvE2ixJeLvMjPmB2w1y oDB2IH1mTGuk7U1SHiD4Dm00Js7i2x1uY3aNxIJMHdZq2DIdKjzx9i8HRNMSGy1lNsxIZG5fzHP NuJye2SmIuq0bAr7Je7TycH/4ZzAgpnSs/P5l5dVPSGV0MyX6ofndto0KfWdUoa5DkevviK5b6W ruzjWMkpCUyuYVHHNLUTL/kpKq8= X-Google-Smtp-Source: AGHT+IHK9VRHh/oKMJeNGnPpbu3Ls15hkJ+JGELwTGVyvDikEOmw4GEDXHpy+/GoKyyxrrkjr7xtmkhL18QF2Uyp5K0= X-Received: by 2002:a05:6102:3ece:b0:5db:47c2:f926 with SMTP id ada2fe7eead31-5dd89135cc6mr1621583137.15.1762405316633; Wed, 05 Nov 2025 21:01:56 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 6 Nov 2025 07:01:44 +0200 X-Gm-Features: AWmQ_bmqmpL1MsVHGr2fljKY_9QR8IrWq4gdwQubVwJCFEb3z_hCOW_RBu7C-z8 Message-ID: Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) To: Seifeddine Gmati Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) Hello! ```php function addStudentLessons(DatabaseTransaction $transaction) { try { $transaction->execute(...); } catch(\Exception $e) { Logger::log($e); throw $e; } } // Application Code: function do_work(DatabasePool $pool): void { using ( $connection =3D $pool->getConnection(), ) { using ($transaction =3D $connection->beingTransaction()) { $transaction->execute('...'); sleep(10); // more work. $transaction->execute('...'); } sleep(10); // more work } sleep(10); // more work } // <=3D=3D broken! ``` Logger::log($e); <=3D=3D reason! In this example, the `Logger` service holds the exception `$e`, which completely breaks the code because the transaction will no longer complete correctly, and it=E2=80=99s unclear when the resources will= be released. This is even more true for stateful applications, where the Logger processes stored exceptions later rather than immediately. Note that I didn=E2=80=99t even use circular references. I=E2=80=99m sure t= hat 90% of PHP developers who see this code won=E2=80=99t even understand what the problem is. And in practice, it will work for about 50% of them and fail for the other = 50%. At the same time, as a programmer, I didn=E2=80=99t do anything particularl= y wrong or make any obvious mistake in this code. It=E2=80=99s just that the logging service holds the exception object for a while. RC-managed objects were designed to create code where the destruction time of an object cannot be determined statically (only at runtime). Automatic memory management is not a primary feature of RC objects, since it can be implemented without reference counting. However, the code in the example pursues the opposite goals: it must guarantee the exact moment a function is called. In other words, the RAII concept is not suitable here. And this situation is typical for PHP stateful applications, where resource control is not managed through RAII. --- Best Regards, Ed