doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

Fix function flock example

Open entrypointkr opened this issue 9 months ago • 0 comments

When I fwrite after ftruncate, the control characters has appended. image

You can reproduce this by:

$fp = fopen("file.txt", "r+b");
ftruncate($fp, 0);
// rewind($fp);
fwrite($fp, "contents");

Also I can confirm that do rewind after ftruncate would fix the issue, therefore this PR is for it.

References:

  • https://www.php.net/manual/en/function.ftruncate.php
  • https://www.php.net/manual/en/function.flock.php#116782
  • https://stackoverflow.com/questions/18255780/fwrite-writes-nul

entrypointkr avatar May 03 '24 18:05 entrypointkr