Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125675 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 qa.php.net (Postfix) with ESMTPS id 6B07C1A00BD for ; Wed, 25 Sep 2024 09:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1727255662; bh=FsfEzi6yjuGJswWuGW3el50eK2beBOJzghkLL9eFbiI=; h=Subject:From:To:Date:In-Reply-To:References:From; b=IBkKLK9tfZkFVi2N0RxI+zkvHzKhBZo+Ftuw3+97+JIuR3ieTlP9XXPkeU/vdLNpw w9gacGWLAjO4Aa85lLIcCzcK5zijw9vw2628SNQotMmYNUdrixU3wKuk+0cuqMpHfZ JSc4/joXMn2vMehyjYUVLFXIfyVdhmsoZN9/NDJvWejYF9iwzIWKklw/XIkzRSh3ep jCYAh42CYTHrgCqaMPIYth2fYNZcoDYk3Wg5XsZ1etkLXEM940tbaflvB4MLRcd0eV hDSRFniZ58Qb/ovqZv0M7n1+j9HPJOMbHHoT5FkL1IKLdHxEpjer8HwWd5+fxAhCnl TmEQN1rKFcZxw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0C93318007B for ; Wed, 25 Sep 2024 09:14:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from ageofdream.com (ageofdream.com [45.33.21.21]) (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, 25 Sep 2024 09:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ageofdream.com; s=ageofdream; t=1727255531; bh=FsfEzi6yjuGJswWuGW3el50eK2beBOJzghkLL9eFbiI=; h=Subject:From:To:Date:In-Reply-To:References:From; b=RYLGyRKo7TeKFsvVKT6A0nX0AqX/8MtDfDwIklSh4LWhJErURIuY1Txbjb8/j2RWZ oE7wMoDlPFGByzkIgKGebX1v5apiL7vjJHJDaKCRigvZvaZ+naalMcmITSKLAcyxxW RoZ72O3RhfOXe77Pqwdm96kWK+bHL2MULy3Ta0JRpiMKI7T6KsRbwIthj2okP1xS8/ aRpfnG83KUziCznVBFlrEnq4TaTx3GJhQd7o71ROvQDmntyitv+V/i/5EhDf//fYoJ KPAf7IjcYvDkCQL4aD9taOWDJJ0SfHD5o5SzedFoxsHOX0JkjR1iPF8dFmg2MuUZSu yXtzq/jojERng== Received: from [192.168.1.7] (unknown [72.255.193.122]) by ageofdream.com (Postfix) with ESMTPSA id 0BD0E25090 for ; Wed, 25 Sep 2024 05:12:11 -0400 (EDT) Message-ID: <3ab9db77462c5f49c7c4a977098ba4677deb363f.camel@ageofdream.com> Subject: Re: [PHP-DEV] [RFC] Change Directory class to behave like an opaque object To: internals@lists.php.net Date: Wed, 25 Sep 2024 05:12:10 -0400 In-Reply-To: <2VnM6xycBpzqzDnAZKWS4zxCSUjvoKywJRiBzTcGhS8axaFS7QwbGNQtjkovo1jQi1XLiEGGTi3KfQfWoxUT527U_-6IGO3092BZdW436q0=@gpb.moe> References: <2VnM6xycBpzqzDnAZKWS4zxCSUjvoKywJRiBzTcGhS8axaFS7QwbGNQtjkovo1jQi1XLiEGGTi3KfQfWoxUT527U_-6IGO3092BZdW436q0=@gpb.moe> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 From: lists@ageofdream.com (Nick Lockheart) On Sat, 2024-09-14 at 15:33 +0000, Gina P. Banyard wrote: > Hello internals, >=20 > I came across the Directory class while doing some code exploration > of ext/standard. > This class is effectively an opaque object for Directory resources, > however it doesn't behave like one, as it has existed since PHP 4. >=20 > As such, I am proposing an RFC to turn this class into an opaque > object. >=20 > RFC: https://wiki.php.net/rfc/directory-opaque-object >=20 >=20 > Best regards, >=20 > Gina P. Banyard I don't suppose we could call the Directory class something else, like "SPLDirectory"? You can't make a Directory with `new` (or at least you aren't supposed to be able to), so any existing code would already get a Directory object with `dir()` not `new Directory()`. There would be no BC break with a rename. Why? It's very easy for someone that doesn't know about the Directory class to create their own class called `Directory`, instantiate it with `new` expecting their autoloader to pick it up, and then getting very strange results. The error will usually be something like, "call to undefined method Directory::MyMethod", which makes developers go nuts, looking at their Directory class, seeing "MyMethod" clearly defined right there, and yet PHP claims it can't find the method. But PHP is finding the **class** because surely, the autoloader loaded it! What actually happened is the autoloader didn't run because the name "Directory" is already registered. But there is no warning or error when someone writes `new Directory();`. Since the built-in Directory class is never instantiated by name, nothing would break by renaming it, since it only gets created by `dir()`. A rename would free up the name 'Directory' so people wouldn't get frustrated with bizarre behavior when they make their own Directory class (which I imagine is very common).