Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129078 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 3AA021A00BC for ; Wed, 5 Nov 2025 05:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762320471; bh=h7oIG61BMfQIPnfbFeO671eKX4YRfIWJMi6384kKV2s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=IGuP8BvAeduEYRjlQiTjcQmgdvIgxjXgBwZ6lCmWGh6QPq+JNM7AYlxpG1lCMHGJF +UTsvn10YbjNczguJooIkHH4uPConjgd7bTjLnO+0g945MWJLOqLavbT/R0TlAfA9w NZ0Mf1PsFTkwx9iMSjCesyTuHrYj/PWoDUN2WCpvugITa70895uw592Ql6iFV7fRaI XP/7SWhJY49ysrWv4wsd855GPWYmy35dovGKwtcyAa131M6MHi+w16kF6xIM1xd1fc esM02ZZUTCqpvYqwDdoz8bKpPTiL8rCzXi0q4IumHTzmumH5PzXVTWfjT4+07D0qSw toERy3+5tBxVw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 096EE180041 for ; Wed, 5 Nov 2025 05:27:51 +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_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-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) (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 ; Wed, 5 Nov 2025 05:27:50 +0000 (UTC) Received: by mail-vk1-f172.google.com with SMTP id 71dfb90a1353d-55964d4ccc1so821819e0c.3 for ; Tue, 04 Nov 2025 21:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762320465; x=1762925265; 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=h7oIG61BMfQIPnfbFeO671eKX4YRfIWJMi6384kKV2s=; b=TsoBDQHyyDMwOeasOvtcQ9p5uBkqBrpVQINjp6R6iJcxbYfjgmYOUPlNvbagIiJPDQ mAircHABaH3SpWdcqJmlEINPzZR4x+RwrVPoewmH/0YOS4AVlAMEEGUU6Sun2dsh44vj eb51CpPsU09aLetq0VtgFbZOdx+woNhRFyROvQhiMqiVf1ozGbgIdlEzsbm/Lgd5S+88 HKNwXbwwlhUwo5hkFerziW2WE5azcCQjJGmYBWG1vv21YYRrhEZ+Wl+xPoig0Xra+3FN 5yxtjRsC2ChkE8kBWM5soSpaC6+dmYcFDKJYX0fSPbiJBUu27yYYPQMh9CVDrbyLHsTQ tIFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762320465; x=1762925265; 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=h7oIG61BMfQIPnfbFeO671eKX4YRfIWJMi6384kKV2s=; b=iF/qeTt6HJXMO8LrTz1Gj8dFoIjYPnujJ6ETy9/pW0GmsLw8AfPD7B+BMGobZ11621 V2zdtVvOZX/G+bxsV5XoufruHG3j3rdKhC9OfMo67H3xHyDrN0y+Tt1N3Kq+3wJUvoxc XVbuVvUh0JJQhcl9mc5JXKl22sggakr/CKDbaf2oZhpTpbqzsjq3S2T7Fh+oMtgwB4JI C9b1EzKBxfMe9OXCeXSGcsXUNrTySW2okbDsSmTcrFOi1wqrqyZ5M6Vg09YMuUf4mmZ3 yuu87WAC/iHLkCwRhSBKh1/IaL72JIz999ZIq2OqI3OX0LLe/ekv7EFnk/sypgY6dzRJ VhXQ== X-Gm-Message-State: AOJu0Yyr0j/4RuC7OLXxr0EhHrXoy5HwkNeVvwl4VSuDbpPbS4s0AAMA IA43Sm55vxL2UdYmF9ul5MlmE7/higV3DcgEarUdkLS5yq0VRZ3l/J2mbaYIVMjw5eocGp4vY1l LQXa0SEEdDn67ZTHVwyUBhDdqUYKAYRE+X1kq X-Gm-Gg: ASbGncvEayQo5p22n/He2z2YCjr0JtJym1CAKQYyTwoXS4x9ywBi9XBu5hBLjCVhcha l2dab73m2vCZ9nNcZGvz5A5EKg7dGvS4fSnZVmaS98bLlXY4rVz4IzQFNI9M5uK72LLRSOnEsR+ wHqw47c+7B+nvDZsRYQY77EJ0QxpzdD2XqYBvWdgxMu2p04LT0bm8wJZwoGVA/qJ5Egecz+pU0b TUh9NwvpPW44msPOJIz0yZiF4obOlBzzVZhrBN8ul6dtf1Xe9DabV1jvM41t0F/bGSOMpADTCdL ztJVU/ZdH72gY2j+ X-Google-Smtp-Source: AGHT+IFR/+e/0fjJxKv9Bi8mZ9rHKmNC/gYdjxTE2iePzxwNxTPv9RzNVuphbKhkcJLB8FZ9ZJLefmj+Y3S2M4XoEHI= X-Received: by 2002:a05:6102:5091:b0:5db:23ce:3db with SMTP id ada2fe7eead31-5dd89120276mr704312137.11.1762320464907; Tue, 04 Nov 2025 21:27:44 -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: Wed, 5 Nov 2025 07:27:34 +0200 X-Gm-Features: AWmQ_bkHl9psX5CgxVCqeGJqngw88R2l_bgogoAZGLcOVa1pVmNIF5hNjMzarW4 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 > A disposal interface has its issues. Although Arnaud Le Blanc has already covered this topic thoroughly, I=E2=80=99d like to approach it from a slightly different angle. Let=E2=80=99s not think of __enter__/__exit__ + RefCount as a problem. Ever= y approach has its own purpose. In this case, there is a clear distinction between Scope logic and __enter__/__exit__ logic. These are two different concepts, and you cannot and should not try to satisfy both RefCount and __enter__/__exit__ conditions at the same time. The purpose of __enter__/__exit__ is to handle the try-catch-finally pattern for a resource regardless of the reference count. Therefore, RefCount is not an issue. (although PHP can automatically issue a warning when attempting to call the method while the reference count is greater than one) If PHP applies unset or __enter__/__exit__ depending on whether an interface is implemented, it will introduce hidden behavior in the code, making it harder for developers to understand what is happening. Compare the two cases: ```php // I know for sure that Scope implements the interface // required to be used with "with" with $scope =3D new Scope() {} // I have no idea whether the File class implements // the required interface or not. It=E2=80=99s unclear what will happen in = the end. with $file =3D new File("...") {} ``` So, in Python you cannot use arbitrary objects in a with statement, only those that implement the __enter__ and __exit__ contract. Therefore, in Python there is no ambiguity in the code. The developer understands that if `with` is used, it means the object definitely implements the required interface, otherwise an error will occur. PHP must guarantee the same behavior. P.S. If I=E2=80=99m not mistaken, a recent RFC was proposed about context manage= rs, which covers exactly this logic. --- Ed