Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98697 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21772 invoked from network); 31 Mar 2017 08:32:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Mar 2017 08:32:34 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 74.125.83.46 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 74.125.83.46 mail-pg0-f46.google.com Received: from [74.125.83.46] ([74.125.83.46:33177] helo=mail-pg0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/70-11319-F141ED85 for ; Fri, 31 Mar 2017 03:32:32 -0500 Received: by mail-pg0-f46.google.com with SMTP id x125so64563998pgb.0 for ; Fri, 31 Mar 2017 01:32:31 -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=req8cTuY281HB269VcP5w0IYXw0JpHMRA4H7urQRRGM=; b=vXELVJmyGpIp6YaGj3z3GayWZNQQdWAk3qJxL+A/Wb9WUmAF09QpCUsv9u0vdfsRLA vEKTosdpTCunuCyvUtEpnbwR4lVe7whWcHt+G7wp69wL5qXIToUkIjqRYjKnx9dQ52vk sn/B8WKzGsF8uEClNjvqk17qOF4wWgrWVcfUAJxI/nU0/WNHMxgYViUbfKYAnEETgeIQ //JP78SmURrUhQi2yeTVr6kEpoKTrrpWRePXsWt5DY47Aj5XcQHYXqNQuJDjamzc98QR rF4q3dbA1RYSxtBqnTruepEhHQ3w0SGASBS3fbpYdXPpk0Usd0uuoOyii3aa3jZS9cL4 3s6g== 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=req8cTuY281HB269VcP5w0IYXw0JpHMRA4H7urQRRGM=; b=CYYkxOKrZGPTDY75kJGBdly4OxWIA9BQUMV6q5Yik3OG83czqZHM1kfLoosV+6OOij HIm1VtajAu48GvJOPCXlI6cgs+Om4VFvUm4uLQWjC9IBcqIMVmGBL0QMN0v5hvivTf12 lDO24ILh5dlpW65dYFX6WEEg+FUWcSGR4CQKGYOtOrx6G8py5xKrlrEz1B5PlirCms2Q jZhEm738rnxHAnJXq4OZhcdlDYeG9lnqbb1UBUX1+PEwLJngyK+5PkTrPPk0h0fnClmQ vyN613z3qnvdGOP5WOfZHZMTJfSXks4FogIGhcM4cAKnf+j73OAdglgTMigaStbpcZLK 22FA== X-Gm-Message-State: AFeK/H29RHWFrLvPlG5n75xkye5EIEJL/hd/dJugDfEPoTV0j+e83s3htFhYGRt6Ocp/vwaDA+ZQ8mkCliyjuQ== X-Received: by 10.99.173.6 with SMTP id g6mr2083744pgf.75.1490949148106; Fri, 31 Mar 2017 01:32:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.145.150 with HTTP; Fri, 31 Mar 2017 01:32:27 -0700 (PDT) In-Reply-To: References: Date: Fri, 31 Mar 2017 10:32:27 +0200 Message-ID: To: Kris Craig Cc: Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary=94eb2c1bef2659fb0a054c02a6fc Subject: Re: [PHP-DEV] Directory separators on Windows From: rasmus@mindplay.dk (Rasmus Schultz) --94eb2c1bef2659fb0a054c02a6fc Content-Type: text/plain; charset=UTF-8 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; } At least WordPress, Drupal and probably most major CMS and frameworks have this function or something equivalent. This function is too trivial to ship as a separate package, but at the same time, it's too error-prone and repetitive for every framework/project to implement (and test) for itself... In my opinion, it's common enough that it ought to just be built-in? On Thu, Mar 30, 2017 at 5:45 PM, Kris Craig wrote: > > On Mar 30, 2017 8:21 AM, "Sara Golemon" wrote: > > > > My first thought is UNC paths. On windows a file server share is > > denoted by \\host\share . if you combine that with relative paths > > produced from PHP, you end up in the dubious situation of > > "\\host\share/path/to/file" <--- wat? > > > > Overall, it smells of magic. > > > > -Sara > > > > On Thu, Mar 30, 2017 at 8:25 AM, Rasmus Schultz > wrote: > > > Today, I ran into a very hard-to-debug problem, in which paths (to SQL > > > files, in a database migration script) were kept in a map, persisted > to a > > > JSON file, and this file was moved from a Windows to a Linux > file-system - > > > because the paths on the Linux system had forward slashes, the files > > > appeared to be missing from the map. > > > > > > Related questions are very commonly asked by Windows users, indicating > that > > > this is a common problem: > > > > > > http://stackoverflow.com/questions/14743548/php-on- > windows-path-comes-up-with-backward-slash > > > http://stackoverflow.com/questions/5642785/php-a-good- > way-to-universalize-paths-across-oss-slash-directions > > > http://stackoverflow.com/questions/6510468/is-there-a- > way-to-force-php-on-windows-to-provide-paths-with-forward-slashes > > > > > > The answers that are usually given (use DIRECTORY_SEPARATOR, use > > > str_replace() etc.) is that by default you automatically get > cross-platform > > > inconsistencies, and the workarounds end up complicating code > everywhere, > > > and sometimes lead to other (sometimes worse) portability problems. > > > > > > The problem is worsened by functions like glob() and the SPL > directory/file > > > traversal objects also producing inconsistent results. > > > > > > Returning backslashes on Windows seems rather unnecessary in the first > > > place, since forward slashes work just fine? > > > > > > Might I suggest changing this behavior, such that file-system paths are > > > consistently returned with a forward slash? > > > > > > Though this is more likely to fix rather than create issues, this > could be > > > a breaking change in some cases, so there should probably be an INI > setting > > > that enables the old behavior. > > > > > > Thoughts? > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > Another option would be to create a function that converts all slashes in > a given input string to whatever the directory seperator should be on that > platform. This way, devs wouldn't have to deal with bulky aliases like > DIRECTORY_SEPERATOR cluttering up their code. > > For example: > > > print convert_seperators( '/some\directory/' ); > > ?> > > The above would output "/some/directory" on Linux and "\some\directory" on > Windows. > > --Kris > --94eb2c1bef2659fb0a054c02a6fc--