Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112245 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43572 invoked from network); 13 Nov 2020 10:31:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Nov 2020 10:31:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 08DC118050B for ; Fri, 13 Nov 2020 01:54:28 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_40,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 13 Nov 2020 01:54:26 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 8CB521FF25 for ; Fri, 13 Nov 2020 09:54:24 +0000 (UTC) To: internals@lists.php.net References: Message-ID: <95df9984-f2cc-9dad-53bb-a31155657620@processus.org> Date: Fri, 13 Nov 2020 10:54:23 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] Why there is no StreamWrapper interface ? From: pierre-php@processus.org (Pierre) Le 12/11/2020 à 23:01, Larry Garfield a écrit : > On Thu, Nov 12, 2020, at 3:25 PM, Benjamin Morel wrote: >> On Thu, 12 Nov 2020 at 19:28, Sara Golemon wrote: >> >>> Honestly, I kind of regard the state of PHP's filesystem libraries to be >>> one big hot mess. I'd really much rather redesign them from the ground up >>> with some BC shims to avoid breaking the world, but I lack the drive to >>> make that happen at the moment. >>> >>> -Sara >>> >> There have been some attempts (including mine) to design a better >> abstraction on top of current PHP filesystem functions, which would be a >> good start, but I think what's missing the most currently is a good API to >> get inspiration from. >> Is there a filesystem library in another language that is considered >> state-of-the-art at the moment? >> >> — Benjamin > I have heard very positive things about Rust's file system API, but have no experience with it myself. > > --Larry Garfield > As Larry said, Rust one is probably a good example, but if I remember correctly, Swift's one is not bad too. Java NIO is probably a good contender as well. But Rust has in my opinion a much better error handling than PHP ever had, so I guess it's easier to have a good implementation for such error prone API (you're too dependent on the OS and hardware for managing files safely, you need a seriously robust error handling for this). I don't trust PHP on that front because you are basically just allowed to ignore and not catch any error and let everything burn without worrying. I think that for a robust file handling API, you probably need something much more strict that forces you to do things well. In that regard, anything such as an option type along with enum errors and a pattern matching would do the trick. Anyway, from my own point of view, when I work with files, the two most important features are a good error handling that cannot be missed (returning false silently when something doesn't work is not a good error handling for me) along with guarantee that operations are atomic whenever possible accompanied with doing everything in streams for performance and memory's sake. Actually, error handling put aside, that's what PHP's file handling is, I guess, but I'm far from being an expert on that topic. That was my two cents, my opinion is that PHP should improve its type system and error handling before starting to improve its I/O standard library. Regards, Pierre