Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129076 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 DFC371A00BE for ; Tue, 4 Nov 2025 19:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762285502; bh=/jBeo2cZCLfdh8x3pJDYzCl0cYiKtBf61TGF03jJ5/Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=TRGU4Ky9xDUrRUUB57jVSs/d2eUkPlegmkHNdInvVnO/xe0wPAv4be5jCP6gm3PYL ht/DORAgqeOQjol7Uc841SRGnpeNsAw8zqvDqaap67ig4NbhwegPun26+TyWmbKn5w ovCH99V7HDBOV9qQPZuSGOebSJFgXdO3A+LgwPM0dOFI3PNJl74TDAfXL0yJHo/5uh lY2hipUCshuqJ81pjgs/ewxQgDCTwJ/21aUWFO/wI24dKT3KNUkhYjvdRnLrfdYPID AYVnH24mGtbldRjf13seG6X1GAJCApsRbP26FkkQFwhDhpT5QnbQU+jY5WCkEyk3zE Y2fBf26oTkjQw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7294F180386 for ; Tue, 4 Nov 2025 19:45:00 +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.0 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) (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, 4 Nov 2025 19:44:59 +0000 (UTC) Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-9310a7b2668so1958046241.3 for ; Tue, 04 Nov 2025 11:44:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=carthage-software.20230601.gappssmtp.com; s=20230601; t=1762285493; x=1762890293; 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=jRv18DFH/AYQslw8flaXMtrV3O3n3a//VqEtL0kQjFc=; b=ujDI96drtCqhnFUOG8zYgYQ4KTMqGm7Jq7Yd/mA4SrpHBtt0fJTfn2t/OtRl+P2DvL lngY2Fl5gBboqNUE75za0GU2uKMBz/Yy68odPWUiZEic8HMAj+7cexUD68k0HYrnJIO1 nmG++nHsnlrpzTR6pJR5u3AibTvz8PQbIoMgydKMT8C+RyeU9JAqwCd8S1tdRN8rWZaO CIYwzesQV3LELDfa2TjpOK3IOj6/E4ZeZwHXBjAJ6MwKZ3ut3PTrBS5cRzZxNxFkc3gx 4FGFndLAEzf+TcTzBbOAI+KaDNfMLfDl9d/2yg5kj+KyuBp4zc7UDafRDYygkmgrWBW+ VtCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762285493; x=1762890293; 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=jRv18DFH/AYQslw8flaXMtrV3O3n3a//VqEtL0kQjFc=; b=TzpkXGvVNq0jGO4b2kmRH8jSkZCqveF5zD682Oqrt+/onSs7gIfiVJvzxgkdb2MHCg bUR4TNn+w/AjC9V7q/zTc+lEdDAFngap1iMOJ8rRDSxYjOAoeFwzCuazehbJ/oXlkQEA JmklAMyPmJW4ykcDmdgpMR09SaxgntGHiS464D1Ns0BmYaUCxud+0S0jgmD6n5aUXQpH RD+UZopyToZpHkbT6Iy2tWeyPsb8YY4QgCQZIvBJNhr11emS2j3Jzk3VeugqD5UZEkQ/ 5pX9opSvcJV5m9jbNdZXTGB23OK6OlQQDJ+KnRWHmwrBPMy7XWi2TF3B3H03qUiux3VL sUvw== X-Gm-Message-State: AOJu0Yzdp8yC4XJthQaGwBQSRE8iHOoYW8uLzhGngkVvSGe4m8YbqxYU T920jTROuzXKPjSEdJ2O87HGKALFDv6ImwxLOqv7BqV95ArS33geUcKlXfPtprm5BEe492Jdslu yEy+5yXW31CbY3Yq1zUwfKoqOH/ZJXKUAPVf9V1MjeQ== X-Gm-Gg: ASbGncvJ/zngoiMeT8rXenhzz/bw1zG43JAWlpkyytwLxNRK2egxeF5nqGEr0aGsp3N fbbdZqHwpfrwTPnaLPtN3xEvI0hpDRzXWIyhFX2DQXzvlTzJCxUd9SyodRUM+Lx1v8LUNChSvxu 2KtrWncUgrIZF4pskb9IrKoOzNhWNGV+l/s6CJvQ5KERwMTO47n0i+HS7wX6gO4Zl2RiBd2Vchu cRve3UmhVQREdh45cvZsOfZjciqaJwvPcklxNEHSgdgN44oK5AW6K8T3/s1X2H9THQxAPs= X-Google-Smtp-Source: AGHT+IHW0/Syc/RI4sSav4jnWgqvXK16/XGGCl5FhO6z+85zrO4bK8AoAnFebTmKWk+1NMimwuaJUErVuTAbE6y3DF8= X-Received: by 2002:a05:6102:32c3:b0:5db:ef30:b74f with SMTP id ada2fe7eead31-5dd88ef4243mr307604137.8.1762285493455; Tue, 04 Nov 2025 11:44:53 -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: Tue, 4 Nov 2025 20:44:40 +0100 X-Gm-Features: AWmQ_bnwWctifWks2taA0E1bp6nIQQfz0HbLNvvNK82I69ymGOPSCpOVStawtZo Message-ID: Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) To: Edmond Dantes Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: azjezz@carthage.software (Seifeddine Gmati) On Tue, 4 Nov 2025 at 10:28, Edmond Dantes wrote: > > Hello all! > > Thank you for the RFC, it has been missing for many years. > If I understand correctly, are you proposing to call `unset` at the > end of the block? > > I see that the **Future Scope** section mentions `Disposable`. > But if your goal is to introduce behavior based on `Disposable`, > wouldn=E2=80=99t that conflict with the logic of the current RFC? > I see a clear pitfall here. > > If you accept this RFC with the `unset` operation, you will later need > a new keyword for `Disposal`, because these are two entirely different > scenarios. > (Should I explain why?) > > In this context, I also see a problem, as if the RFC is trying to > introduce two different features into the language: > > 1. **Scope** =E2=80=93 a visibility area. It is the scope that has the `u= nset` logic. > 2. **Using** =E2=80=93 a guaranteed call of a disposal function. > > Because of this, logical issues are likely to arise. If the RFC=E2=80=99s= goal > is unclear and it tries to cover both tasks, the solution risks losing > its clarity. > > P.S. > Regarding the questions in the Open Issues, option A seems to have > more explicit behavior than option B. > > --- > Best Regards, Ed Hello, Thank you for the feedback. Regarding the `Disposable` interface: introducing it in the future won't require new syntax. The `use` construct can work with both `__destruct` (current behavior) and a future disposal interface. The idea is to introduce an interface like: ```php interface Disposable { public function dispose(?Throwable $throwable =3D null): void; } ``` With `use`: ```php use ($foo =3D new Something()) { // work } // ->dispose(null) called on success, ->dispose($exception) on failure ``` This mimics Python's context manager protocol. The `dispose()` method would be called before `__destruct`, allowing objects to distinguish between successful completion and failure. However, there's nothing stopping us from shipping without it. The lock example in the RFC doesn't need this, locks are freed automatically in `__destruct`. The initial version relying solely on `__destruct` works fine for most use cases. **On the name "Disposable"**: I'm not really a fan of this name myself. It was just my initial thinking when trying to copy Hack. We can come up with something better later. **On Hack's approach**: Hack has a `Disposable` interface, but it works differently: disposable objects must maintain refcount=3D1, can't be assigned to properties, and functions returning disposables need `<<__ReturnDisposable>>`. This is enforced statically by their analyzer. At runtime, they're just regular PHP objects. We can't replicate this in PHP. **The refcount problem**: A disposal interface has its issues. Once `dispose()` is called, there may still be references to the object somewhere, leaving it in an undesirable state, unless we add a way to enforce refcount =3D 1. A disposal interface without exception awareness brings limited value. But with `?Throwable`, it becomes useful: ```php use ($transaction =3D $ctx->beginTransaction()) { // work } // Transaction::dispose(?Throwable) called, then __destruct ``` Without `dispose(?Throwable)`, the transaction can't know whether to commit or rollback, `__destruct` alone can't distinguish success from failure. **The key point**: the initial version (relying on `__destruct`) and a future disposal interface don't conflict. Thanks, Seifeddine Gmati.