Linked Questions

Popular Questions

Why can PHP 7.3 on Windows rename an open file?

Asked by At

I have this code snippet:

<?php

$fh = fopen(__DIR__.'/foo', "w");
fwrite($fh, 'one');
rename(__DIR__ . '/foo', __DIR__ . '/bar');
fwrite($fh, 'two');  
echo file_get_contents(__DIR__ . '/bar');

Output when I run this with php-7.1.26-nts-Win32-VC14-x64:

Warning: rename(C:\test/foo,C:\test/bar): The process cannot access the file because it is being used by another process. (code: 32) in C:\test\test.php on line 5  
Warning: file_get_contents(C:\test/bar): failed to open stream: No such file or directory in C:\test\test.php on line 8

Output when I run this with php-7.2.15-nts-Win32-VC15-x64:

Warning: rename(C:\test/foo,C:\test/bar): The process cannot access the file because it is being used by another process. (code: 32) in C:\test\test.php on line 5
Warning: file_get_contents(C:\test/bar): failed to open stream: No such file or directory in C:\test\test.php on line 8

Output when I run this with php-7.3.1-nts-Win32-VC15-x64:

onetwo

I think the responsible code is here and here, but I can't identify a change that might be responsible for this behavior.

Related Questions