|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24503 writing newlines and multiline comments produces strange results
Submitted: 2003-07-04 17:52 UTC Modified: 2003-07-05 07:12 UTC
From: troublegum at woltlab dot de Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5CVS-2003-07-04 (dev) OS: Windows 2000 Professional
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: troublegum at woltlab dot de
New email:
PHP Version: OS:


 [2003-07-04 17:52 UTC] troublegum at woltlab dot de
OS: Windows 2000 Professional
Server: Apache 1.3.27
PHP: Version 5.0.0b2-dev (cvs snapshot 07-04-2003) as apache module

I wanted to create .php files dynamically.
I tested the following test-script:

Reproduce code:
$variables = array(1,2,3,4,5,6);
$comments['comment1'] = "test1";
$comments['comment2'] = "test2";
$comments['comment3'] = "test3";

$fp = fopen("./file.php", "w");
//fwrite($fp, "<?php\n/*\ncomment1: ".$comments['comment1']."\ncomment2: ".$comments['comment2']."\ncomment3: ".$comments['comment3']."\n*/\n\n");
fwrite($fp, "<?php
comment1: ".$comments['comment1']."
comment2: ".$comments['comment2']."
comment3: ".$comments['comment3']."


// write variables to file
fwrite($fp, "\n");
foreach($variables as $key=>$val) {
	fwrite($fp, "\$var_".$key." = \"".addcslashes($val,"$\"\\")."\";\n");
fwrite($fp, "\n?>");

// close file and show results
echo "file written<hr />\n";

Expected result:
The expected content of the file "./file.php" should be the following:
comment1: test1
comment2: test2
comment3: test3
$var_0 = "1";
$var_1 = "2";
$var_2 = "3";
$var_3 = "4";
$var_4 = "5";
$var_5 = "6";

Actual result:
Instead, the content which is written to "./file.php" is the following:


comment1: test1

comment2: test2

comment3: test3

$var_0 = "1";
$var_1 = "2";
$var_2 = "3";
$var_3 = "4";
$var_4 = "5";
$var_5 = "6";


So it is not surprising that show_source for this file results in Warning: Unterminated comment starting line 2 in c:\dev\htdocs\php5\fw.php on line 21


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-05 03:27 UTC]
try fopen("file.php", "wb") instead.
 [2003-07-05 06:11 UTC] troublegum at woltlab dot de
Well, this works for me now. Thank you.
I found this in the fopen manual entry. It was recently added, wasn't it?
> It is strongly recommended that you always use the 'b'
> flag when opening files with fopen().
 [2003-07-05 07:12 UTC]
Not really a bug in PHP, but a text-mode translation issue.
Yes, that comment was recently added to the manual pages.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 02 19:05:54 2022 UTC