php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46680 Files created in wrong directory (include path vs current working directory)
Submitted: 2008-11-26 10:15 UTC Modified: 2009-01-23 09:45 UTC
From: ant@php.net Assigned: zoe (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.3CVS-2008-11-26 (snap) OS: *
Private report: No CVE-ID: None
 [2008-11-26 10:15 UTC] ant@php.net
Description:
------------
The following tests were ported from 5.2.X and do not work as 
expected on 5.3. The tests all create a test file and expect it to be 
created in an include directory. Instead it looks like the file is 
being created elsewhere This particularly affects file_put_contents() 
with the FILE_USE_INCLUDE_PATH flag set, and also fopen(...).

Reproduce code:
---------------
See the tests now checked into CVS:

ext/standard/tests/file/file_put_contents_variation4.phpt
ext/standard/tests/file/file_put_contents_variation5.phpt
ext/standard/tests/file/file_put_contents_variation6.phpt
ext/standard/tests/file/fopen_variation5.phpt
ext/standard/tests/file/fopen_variation7.phpt
ext/standard/tests/file/fopen_variation8.phpt
ext/standard/tests/file/fopen_variation9.phpt
ext/standard/tests/file/fopen_variation12.phpt
ext/standard/tests/file/fopen_variation16.phpt
ext/standard/tests/file/fopen_variation17.phpt

Expected result:
----------------
See expected output in the PHPTs.

Actual result:
--------------
See the test results from running the PHPTs.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-09 19:37 UTC] cellog@php.net
first of all, the change from PHP 5.2 is the addition of php_resolve_path, which is Dmitry's work.  Second of all, most of the tests are checking for *broken* behavior which is fixed in PHP 5.3.

file_put_contents('blah', 'whatever', FILE_USE_INCLUDE_PATH);

should not arbitrarily create the "blah" file in the first element of the include_path.  file_get_contents('blah', true) does not work this way, it scans include_path for the file, and if not found, it tries as a fallback to search in the current directory, and only then does it fail.  This is correct behavior - the file should be created in the current directory if it does not already exist in the include_path.  The addition of the fallback was added in PHP 5.3, it seems.

The fopen tests also assume that fopen() with include_path parameter for read will not check the current directory.

So we have a larger dilemma - the default include_path has the current directory as the first element, and thus the functions that use include_path for writing were acting as if they were doing the right thing, when in fact they were making an arbitrary assumption about where to put things.

None of this behavior is documented, so it is questionable what is the right way to do things.

In other words, Jani is wrong to imply that anything I did caused the problem, and should probably apologize, but I won't hold my breath.

I'm assigning to Dmitry under the assumption he will want to do the ultimate commit, but will raise this on internals@
 [2008-12-10 12:19 UTC] dmitry@php.net
I suppose the behavior in 5.3 is proper and the tests are wrong.

In 5.3 Both fopen() and file_put_contents() first look for file in include path and in case of failure create new file in current working directory. May be it should be changed to create it in first element of include_path, but what should php to do if such directory doesn't exist... Creation file in "script" directory (as 5.2 does, and what tests expect) makes no sense.

BTW I don't see a lot of sense in usage of include_path with "create" functions at all.
 [2009-01-03 15:52 UTC] zoe@php.net
If the behaviour is correct in 5.3 the tests need to be fixed. I'm have re-opened and assigned to myself to fix. 
 [2009-01-19 16:20 UTC] zoe@php.net
Fixed ext/standard/tests/file/file_put_contents_variation5.phpt

Adding:

filetype_variation2.phpt
 [2009-01-23 09:45 UTC] zoe@php.net
Fixed tests
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC