Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129088 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 5A9E81A00BC for ; Wed, 5 Nov 2025 12:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762347221; bh=ZkgNnvctPfEgxai4xRw1NtnfVnIMtGIfkeLC4mQJJh0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=HSCqbS3GgNDuMNR0m9eS9tn9dVI5bh1HtZhdNqddG7Mq1rHSqMN9ibQR8cPRozOXI tFHVqooEUwnWkpGARDyBxqMickGSxoivjd+mKxJ9VFX/Hl1bAyWP3/mmhb6O21ePMC b5RP+kmtCZP+j1ELw8hT7WeHAGX1H7Z74wk7KhiB5zQ+3xFVa9TVV9lA7gJBkW+7ZW D80qD4DCvMbgDW+uHfPZp+d6BO1iiMWmQb1qQQ2B3XSfsbqhgfPpAVprjRVWbFe2dr iyyH4FWGqj6z9gzTcIbSxGDy6gnR4gxRNa9S8OpJmr2j1C8reBKu4PVWOcb+uwnbyt QbDSGpdepfDrw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4FAAB180078 for ; Wed, 5 Nov 2025 12:53:41 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 12:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1762347214; bh=8JoZL+EXjI+bOt1I2TOYwQE92GXAOKKvqLBEpXt2Kkg=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=a7p3OSXWAouFLrajaab2MT0mvSgUbuCP/cMNLVqaD/wsF09sXdrY2m9jy2JQopZuv FBpjt4K4Aw6x1u9iYr6Ulzjz06Ovv1AT2XxP0DBUA6BpaypT8TOCyZ+K6Ih3GrYPJQ jUEqSnkxU1N1tB+YypK2pusG1XCutO6Ffk5G9MZ6ys0ZZLDJ1siYr8D0vpu3M3Yr6f KGz8Sdw9XL02YFy7k3F1/QoTWXjQBtDNbi/8WEeaqUf1OGfaZz8RmcC4gd6Vj8qRtT WcQJ9tFHIkjHl5PgUPBt9n4D99yuqhdPO2XMi8+YvOT7nxjr54spMIgwJGx6os+DSz Ybxf1QdwvNCWw== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 05 Nov 2025 13:53:34 +0100 To: Ben Ramsey Cc: Seifeddine Gmati , internals@lists.php.net Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) In-Reply-To: References: Message-ID: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-11-04 03:08, schrieb Ben Ramsey: > In general, I support this RFC. I’d like to see examples from other > programming languages, though. You mention C# and Hack above. Can you > elaborate in the RFC on how they implement this functionality? What > about other programming languages? I know some (Rust maybe?) are scoped > to blocks by default. Please have a look at Seifeddine's previous reply to Edmond (https://news-web.php.net/php.internals/129076) and my reply to Arnaud that I just sent (https://news-web.php.net/php.internals/129087). There are two things to consider when comparing against other programming languages. PHP's semantics do not exactly fit any of these, which means that transferring some concept from another programming language directly does not work. 1. Scoping: Many programming languages with explicit variable declarations are block scoped. This includes Rust (which you correctly mentioned), but also C, C++, Java, JavaScript (with let and const). Some of them allow shadowing variables from the scope and some don't. 2. Handling of Lifetimes: As I mentioned in my reply to Arnaud, PHP is pretty unique in the list of programming languages with automated memory management in that it does not primarily use an “unpredictable” garbage collector for memory management, but instead uses reference counting with reliable destructor semantics (that are documented). This is different from e.g. Java where the so-called “finalizers” run at an unpredictable point in time when the GC feels like cleaning up an object. PHP's semantics are close to those of C++ (where this kind of memory management is called RAII) or Rust. For this reason, PHP just needs some generic “syntactic sugar” for `unset()` that is compatible with all existing functionality using `__destruct()` for those RAII semantics. Best regards Tim Düsterhus