#28338 [Opn->Bgs]: CGI include/require (realpath) mishandles relative paths

From: Date: Sun, 09 May 2004 18:24:48 +0000
Subject: #28338 [Opn->Bgs]: CGI include/require (realpath) mishandles relative paths
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-59435@lists.php.net to get a copy of this message
ID: 28338 Updated by: wez@php.net Reported By: mzajonc at pomona dot edu -Status: Open +Status: Bogus Bug Type: CGI related Operating System: Linux Redhat 7.2 PHP Version: 5.0.0RC2 New Comment: This is expected behaviour with the CLI version of PHP. Previous Comments: ------------------------------------------------------------------------ [2004-05-09 19:57:46] mzajonc at pomona dot edu Description: ------------ It appears that when running php from the command line relative paths such as require("../include/test.php") do not function the same in php4.2.3 and php5.0.0RC2. Relative paths in php5 are computed relative to the current directory not relative to the script. This causes commands (typically run in crontab) like php -f /www/foo/bar/test.php to break if test.php has require/include statements that are relative. Reproduce code: --------------- The test script (located: /www/www.test.com/test/test.php): <?php echo realpath("../test/test.php") ?> From command line: $ cd /www $ php -f /www/www.test.com/test/test.php Expected result: ---------------- /www/www.test.com/test/test.php Actual result: -------------- When php4 is used, the output is as expected. When php5 is used, realpath fails and returns FALSE. It appears to consider realpath("../test/test.php") to be "/test/test.php" (given current directory of /www). However, if you do "cd /www/www.test.com/test" and then run the same command, the realpath returns what is expected (since script location is the same as the current directory). ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28338&edit=1

« previous php.bugs (#59435) next »