Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121959 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59730 invoked from network); 8 Dec 2023 09:09:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Dec 2023 09:09:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E8CC8180040 for ; Fri, 8 Dec 2023 01:09:16 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (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 ; Fri, 8 Dec 2023 01:09:13 -0800 (PST) Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-1faf46f96ebso1074803fac.1 for ; Fri, 08 Dec 2023 01:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702026539; x=1702631339; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=dC33Nzbcxc2nCCG7jBxt1i6KGPoVDPpWp6sJ2qNdaOI=; b=mwCkVVue/HQymStwEld+rVkKqWMp5Q7oRaLD72itqe1WTplNViBv+qKbCCiIouDXR6 3mdfr1UVd251SfX6LpHCvK23MN0UW9aqp1xXU2rfImc6rbX7W6Gi2F5MCzsu8H8IyoJH S301zzZK2ctvJhqQxSA8MpQXGAsndhef0+2KNobaCgYKmc/jNFNEJAcKMaXypDjysXFu s0gvczDAlQRqDrjcOnQItBWw+lLyNmELz3AA5NdCL1n+lSTN3SdJRiYphHfVQOcMAgGz PDnkITXI5lSMlS9wOBgDDmhGc+JKkW72iFpfd5JwaR6dbiDCOsGMrXJW130mikaggvcf o3mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702026539; x=1702631339; h=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=dC33Nzbcxc2nCCG7jBxt1i6KGPoVDPpWp6sJ2qNdaOI=; b=DA8oIeh3IbCFXFrrs1REW1wdoBzq1VCYKizqRCURyyyABm/CN+C9GOKOiZKyBxaajS fWOEE6+pekavuYKQ/ZzTfpe5/rvCKAxWb7i8CA3+b0Mip6tA6lMNbWKXYd0m0r4sdtiy iLz63BKs2WMTRlzcttCip7otDISXBpz9vdolS6GrcNWMMezE5qvZsNKxArip8HpNq3Gj GKhMskbXPHdpKWL3FwsedloEjheBWg+wfoGWCllzukHJia3MEdbuWESqQ3ZhFD78v/zt y7NEQrd5ft6Rjbm3Diqqr4cFl/YqJfEP8Viru5ZMMhgBfrHisRTZW4NwijmqTbM4lhGE m9Xw== X-Gm-Message-State: AOJu0YxHoU2D7jlKYsNWxbhirB1jlJRoxQkaI4y5vfA1TGF2b58g8VXD cG0XOXsCBOZPVZVS+6A5pLG8E/Gy+tPo88+zpzo= X-Google-Smtp-Source: AGHT+IFDM3VVyOlB35rkKNam9U94q6CYRWJ2YDKZY7XnVhLHCYttwpaI7HROklVj3OxBqsSiEcTMnHikzAjmj2akWU8= X-Received: by 2002:a05:6871:4e42:b0:1fa:fec3:8c41 with SMTP id uj2-20020a0568714e4200b001fafec38c41mr4261540oab.54.1702026539115; Fri, 08 Dec 2023 01:08:59 -0800 (PST) MIME-Version: 1.0 References: <8f4e3274-6489-4378-82db-fb4829770196@gmail.com> In-Reply-To: <8f4e3274-6489-4378-82db-fb4829770196@gmail.com> Date: Fri, 8 Dec 2023 09:08:48 +0000 Message-ID: To: Niels Dossche Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000432a59060bfbef21" Subject: Re: [PHP-DEV] Filesystem path APIs From: devnexen@gmail.com (David CARLIER) --000000000000432a59060bfbef21 Content-Type: text/plain; charset="UTF-8" Hi Niels, On Wed, 6 Dec 2023 at 19:20, Niels Dossche wrote: > Hi internals > > I'd like to start a pre-RFC discussion about filesystem path APIs in PHP. > The reason I bring this up is because of this recent feature request: > https://github.com/php/php-src/issues/11258 > > The feature request is about the following: > We already have some functions to work with paths in PHP, e.g. basename, > dirname, realpath. > We do not have some common path APIs that you can find in other languages > like: path_join to join paths and path_normalize to normalize paths. > > As not everyone may be familiar with such functions, I'll explain them > briefly. > > **Proposed Functions:** > > 1. path_join(string... $components): string; > This function concatenates the components with a / (or \ on Windows) > between them and normalizes the path. > If the resulting path is empty then it'll return "." to indicate the > current directory. > You may be wondering "Isn't this just implode?". Not really, it normalizes > the path too, which means that components like "." are removed from the > path, redundant slashes are removed, and if there are ".." components then > they remove the previous component from the path. > > It's also not the same thing as calling realpath after doing implode: > realpath would not work for non-existent paths and it would allow escaping > from the root. > To demo the root escape problem: > path_join("..", "foo"); yields "foo" > Whereas realpath("../foo"); yields the absolute path of the "foo" file one > directory up. > > Note: This function does not do any I/O. > > 2. path_normalize(string $path): string; > > This function only does the normalization part described above. > Note: This function also does not do any I/O. > > **Examples:** > > ```php > // Example usage of path_join > $result = path_join('dir1', 'dir2', '..', 'file.txt'); // Resolves to > 'dir1/file.txt' > > // Example usage of path_normalize > $normalizedPath = path_normalize('dir1/../dir2'); // Resolves to 'dir2' > ``` > > > I think these would be great additions to PHP as working with paths and > files is a core part of any programming language. > > > Seems like it, is there an argument to be made to, let's say, in the performance side ? --000000000000432a59060bfbef21--