ID: 41609 User updated by: zoe at uk dot ibm dot com Reported By: zoe at uk dot ibm dot com Status: Open Bug Type: Filesystem function related Operating System: Windows XP PHP Version: 6CVS-2007-06-06 (snap) New Comment:
Hi Sorry for the delay in replying - it took some time to get PHP to build on Windows :-). I can confirm that this patch makes the behaviour of file_put_contents() consistent with that of fwrite()with unicode.semantics=1 in PHP6. It doesn't seem to have regressed anything else so please would you commit it? The extra flags would still need to be added to the docs. Previous Comments: ------------------------------------------------------------------------ [2007-06-11 20:31:36] [EMAIL PROTECTED] "file_put_contents creates a file with \r, whereas using fopen() doesn't. I tried using "wb" in fopen and got the same result." file_put_contents should be used with the new flag. I'm not sure what we should do for fopen, I think we should make it consistent. About forcing the binary mode if a binary string is given, this patch should do the trick for file_put_contents: http://blog.thepimp.net/misc/patches/php/bug41609_force_binary.txt ------------------------------------------------------------------------ [2007-06-11 20:16:04] zoe at uk dot ibm dot com "Having to specify the mode just like you do with fopen is clear and not confusing." Well - this made me think of trying something else. In the following test case: <?php $file_path = dirname(__FILE__); $buffer = "text\nline of text\n"; $nbytes_fpc = file_put_contents( $file_path."/data_fpc.tmp", (binary)$buffer); $fh = fopen( $file_path."/data_owc.tmp", "w"); $nbytes_owc = fwrite ($fh, (binary)$buffer); fclose ($fh); echo "Bytes fpc = $nbytes_fpc Bytes owc = $nbytes_owc \n"; ?> file_put_contents creates a file with \r, whereas using fopen() doesn't. I tried using "wb" in fopen and got the same result. The interesting thing is that this behaviour is only seen with unicode.semantics=1, when unicode.semantics=0 the two files in the tescase above are identical. I'm not sure whether this makes it a doc or a code defect :-) Just more information.... ------------------------------------------------------------------------ [2007-06-11 18:25:38] [EMAIL PROTECTED] "I don't see that as magical.. If a binary string is given, you want it writen as-is, IMHO. I'm classifying back to a PHP bug, because I feel this needs more discussion." Yes, but it is still magic as it introduces possible confusions and wtf factors. Having to specify the mode just like you do with fopen is clear and not confusing. It is only in Unicode mode so no BC involved either. ------------------------------------------------------------------------ [2007-06-11 17:47:11] [EMAIL PROTECTED] "I'm pretty sure that FILE_BINARY solves your issue. It may use it automatically when a binary string is given, but I would find that trickier (magic++)" I don't see that as magical.. If a binary string is given, you want it writen as-is, IMHO. I'm classifying back to a PHP bug, because I feel this needs more discussion. ------------------------------------------------------------------------ [2007-06-11 12:15:56] [EMAIL PROTECTED] "*IF* there is some work needed on the docs is the right process to open another defect?" Good point, there is a lot of work to be done regarding php6 behaviors of each function. I'm not sure what the phpdoc team decided but I will let them comment here, if required. changed to open + documentation problem. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/41609 -- Edit this bug report at http://bugs.php.net/?id=41609&edit=1