Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98680 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52030 invoked from network); 30 Mar 2017 14:15:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2017 14:15:41 -0000 Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.51 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.213.51 mail-vk0-f51.google.com Received: from [209.85.213.51] ([209.85.213.51:36140] helo=mail-vk0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/B7-10047-C031DD85 for ; Thu, 30 Mar 2017 09:15:40 -0500 Received: by mail-vk0-f51.google.com with SMTP id s68so55817510vke.3 for ; Thu, 30 Mar 2017 07:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=yrxW92zL2WxeVc36wzYA3hziP+luGoE+EvSKzMfCrCk=; b=JNZ1YTxxistj5I3GAvsw6ab5tTjVGNTNKa+ugr5puxaaYCyJQJ6U5yOLO+76dqKB4C EAhfBw0jL0qg3gGmY8acxDi4cUg94XN3+xKPjZF++xpkA1paqDSVsPO58eNbrwaN6wQZ dAstjwKWAbAQkQE19m10gIqq2ElIjQsg37DuPx+feY/T5GiFqBx6ohOxjD1pqAlZ6qo9 FjqtPYNXbu9DCtgxzZp7SDqqV/aXnwwVE/WTRu+cwCbmVixgOHwPpZd46PsqAkU5poBO DmltQoTzVvHmYkAV0UucAPG67FLk5zVhuGt53dgUv07cJtyyOL3x/ro4g0VEECrOoNm4 LFVw== 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=yrxW92zL2WxeVc36wzYA3hziP+luGoE+EvSKzMfCrCk=; b=dFiY6pJcts9xZb8Y8sRGwz1noTBVbOAEgfEFINDn0wKsgRxmfVmcCu8NFxY51oa+6b NKHObb6a/llE1lCmx+Bt8eiZIxCzVVtE0rvk0gx76gZNDyu6TrrVag9P1tQ5+kxk5Jwq Q8UpUelKwJ3tVLQnjHjRlp64I2wu3+NZHU3StRBoRNKeQT/7oTETa4WTVMpe7aXw6wZ6 Ihx5b0Il2oCPDzy+GsRk889OEXv5sOgxw9GQhcPMCgjSqfOS4cm9DWZuhOqpr2vPDWvY 8TsTM5pakeW33N98Xnwqn26SzSloGQt6rjWJh+AfkP22blDwkxhNP4tukejNVt9uDTQ3 KhyA== X-Gm-Message-State: AFeK/H1LpdS1YiDnmU0+Jg1sFzamhqVijfvhPdpvG/aZg2Mf1Wfd7HD+Uqi3XtnwK0GKwmDdvN8VyEkSdkIcZA== X-Received: by 10.176.64.226 with SMTP id i89mr3622167uad.164.1490883336889; Thu, 30 Mar 2017 07:15:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.91.84 with HTTP; Thu, 30 Mar 2017 07:15:36 -0700 (PDT) Received: by 10.176.91.84 with HTTP; Thu, 30 Mar 2017 07:15:36 -0700 (PDT) In-Reply-To: References: Date: Thu, 30 Mar 2017 21:15:36 +0700 Message-ID: To: Rasmus Schultz Cc: PHP internals Content-Type: multipart/alternative; boundary=94eb2c1243c2b2703e054bf353e7 Subject: Re: [PHP-DEV] Directory separators on Windows From: pierre.php@gmail.com (Pierre Joye) --94eb2c1243c2b2703e054bf353e7 Content-Type: text/plain; charset=UTF-8 On Mar 30, 2017 8:25 PM, "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? It is true (works) only on Windows because PHP does the conversion transparently for you. It will miserably fails if your json string are processed as paths with other tools or languages not doing this magic for you. Cheers Pierre --94eb2c1243c2b2703e054bf353e7--