Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98713 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7749 invoked from network); 1 Apr 2017 09:13:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2017 09:13:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.192.169 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.192.169 mail-pf0-f169.google.com Received: from [209.85.192.169] ([209.85.192.169:36847] helo=mail-pf0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/10-02743-83F6FD85 for ; Sat, 01 Apr 2017 04:13:29 -0500 Received: by mail-pf0-f169.google.com with SMTP id o126so14412212pfb.3 for ; Sat, 01 Apr 2017 02:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=9613AdyQl33Qde9U40TBuzp7lEOrl2kRDqBfaY+++us=; b=ZvhLL/b9sA3oJNOQNq4vdcS0JFEn9d01iTOKORgIjhE1ZZoz347jdowKEm8EfJUp7R xVk/hEoBbOJC/jLYQn3apvZ9RWEPomkdPpUa2mEyz83SjjnbHl+DmlJ66ep99YhP+0YG cGJ/q/b4dYenZB/TUs96xr1GKr6VZCW+NpGa9MGMzunAaWVz68h69pXc2pvJje2ksUaq Jy6VcbXXB6qO6yhkXrTfJXzUXMnyraVcCFFaJdfQZ3Gt9ggzwaLGWFAdhJ8met+Io2Kj tAius3k1bYnmXWJO+urke+VdNjZE4JbB1y3XpOo3wRy19xACY9CFifwhWLje0SPdXvwe VSPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=9613AdyQl33Qde9U40TBuzp7lEOrl2kRDqBfaY+++us=; b=qPKu5PljkHYpNyiLSb9JDUR6P0SquVxFyH0Lm42Lfm+iwZiO2q1EyvITcNZMWlqTLo ddrq9pcuP1262OtQ69Sz7cUn3k7Dola+3Vkbs5yCNZknYZ8LJxKPfxDEtUX4yJVKg+ve eYXOw5DZG9n/ofsieNDJmYMbLxghp8Zxurykn0/XhKhcIWQn62C16LpwmKwasGVZVluC F+lKczpdBqGUOONnEC7aY5yd294+8OhjAhbUtIBrIQwTy0BPrn/jYPyXJSnA0N9TQ2f5 nd5TzHjLfhUZVa3QdVvfgARz/mQqUKA8OzF7W+OtTTqcF2v9f1/SPhX2gUDX33XesI/P 4AzQ== X-Gm-Message-State: AFeK/H2gF8TRMsFidRDuaKzuRQYJUOCuySKojgXm5ZRq5IqaJ3cIu/5r7PUkDXbPWCadWOqLPt7dWYOeFbhabw== X-Received: by 10.98.22.71 with SMTP id 68mr6544583pfw.233.1491038005159; Sat, 01 Apr 2017 02:13:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.145.150 with HTTP; Sat, 1 Apr 2017 02:13:24 -0700 (PDT) In-Reply-To: References: Date: Sat, 1 Apr 2017 11:13:24 +0200 Message-ID: To: Pierre Joye Cc: Kris Craig , Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary=94eb2c0362f0a50260054c175688 Subject: Re: [PHP-DEV] Directory separators on Windows From: rasmus@mindplay.dk (Rasmus Schultz) --94eb2c0362f0a50260054c175688 Content-Type: text/plain; charset=UTF-8 > Also ucfirst is useless (or any case operations) It's not useless, if you want a normalized path on Windows, it has to include a drive-letter, and Windows FS isn't case-sensitive. > Right now realpath will fail if the path does not exist I know, that's one reason I don't use it. It kind of solves a different problem, e.g. resolves ".." and "." elements in paths... as a rule, I don't ever use relative paths, but it would certainly be nice to have a realpath() that works for files that haven't been created yet. I don't think you can simply make realpath() also normalize the path, as this would be a breaking change? I guess an improved realpath() could be used internally as part of a normalize_path() function, but it's not enough on it's own, since the real path will still have platform-specific directory-separators, so a normalize_path() function would still be useful if realpath() gets improved. So to summarize, a normalize_path() function should: 1. Fully normalize to an absolute path with no platform-specific separators 2. Have corrected case (for files/dirs that do exist.) 3. Have normalized (upper-case) drive-letter on Windows There's also network file-system paths on Windows with a different syntax to consider? I don't know much about that... On Fri, Mar 31, 2017 at 11:40 AM, Pierre Joye wrote: > On Fri, Mar 31, 2017 at 3:32 PM, Rasmus Schultz > wrote: > > Well, this is the opposite of what I'm asking for, and does not address > the > > case where paths have been persisted in a file or database and the data > > gets accessed from different OS. > > > > I understand the reasons given for not changing this behavior in PHP > > itself, so maybe we could have a standard function that normalizes paths > to > > forward slashes? e.g. basically: > > > > /** > > * Normalize a filesystem path. > > * > > * On windows systems, replaces backslashes with forward slashes > > * and ensures drive-letter in upper-case. > > * > > * @param string $path > > * > > * @return string normalized path > > */ > > function normalize_path( $path ) { > > $path = str_replace('\\', '/', $path); > > > > return $path{1} === ':' > > ? ucfirst($path) > > : $path; > > } > > Also ucfirst is useless (or any case operations). realpath goes > further down by solving ugly things like \\\\\\\ or ////// (code > concatenating paths without checking trailing /\. > > > At least WordPress, Drupal and probably most major CMS and frameworks > have > > this function or something equivalent. . > > Now I remember why they have to do that. > > realpath is not fully exposed in userland. virtual_file_ex should be > used and provide the option to validate path or not. Right now > realpath will fail if the path does not exist. I would suggest to > expose this functionality/option and that will solve the need to > implement such things in userland. > > ps: I discussed that long time with Dmitry and forgot to implement it, > I take the blame for not having that in 7.x :) > > Cheers, > Pierre > --94eb2c0362f0a50260054c175688--