paragonie / random_compat

PHP 5.x support for random_bytes() and random_int()

Home Page:https://paragonie.com/projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed opening cast_to_int.php

hald9000 opened this issue · comments

On Windows, with PHP 5.6.31.0, I'm getting an error from my WordPress 4.8 installation that reports:
'require_once(): Failed opening required 'C:\CustPub\PhsMobileCom\WebSite\wp-includes\random_compat/cast_to_int.php'.

The paths seem not to be Windows compatible as line fails during the execution of "require_once $RandomCompatDIR.'/cast_to_int.php';". While it appears that folks in various articles indicate mixing of forward and backward slash in a path should work on Windows; I can tell you it just does not on my Windows Server 2012 R2 (with all latest patches). This path issue also seems to be true for "byte_safe_strings.php" and possibly "error_polyfill.php" too.

I'm a sysadmin and don't really get into this level of PHP code for Wordpress installations so I'm not sure what to recommend to fix this. It looks like this could be a large issue across this project.

However, for the purposes of fixing Wordpress, changing the three require_once lines for byte_safe_strings.php, cast_to_int.php and error_polyfill.php to a backslash instead of a forward slash seems to have resolved my issue. I'm guessing the IF THEN ELSE flow of code execution, from the perspective of Wordpress, ends up not executing other code that potentially also has slash direction mixing issues in path strings.

$RandomCompatDIR is set equal to "dirname(__FILE__)" which correctly handles the slash direct for *Nix and Windows according to PHP Docs.

This article on http://stackoverflow.com/questions/1959772/proper-way-to-set-php-include-path-for-nix-and-windows talks about this issue and indicates the use of the predefined constant DIRECTORY_SEPARATOR as THE solution -- again although some postings in the PHP DOC indicate the slash direction does not matter.

So I changed the three lines to:

require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'byte_safe_strings.php';
require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'cast_to_int.php';
require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'error_polyfill.php';

thus far all is well with Wordpress with PHP on Windows! I'll be monitoring the PHP error log over the next few days to see if more errors pop-up.

commented

The next release should have this fixed (which I'll tag today).