php.net |  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
 [2003-07-04 17:52 UTC] troublegum at woltlab dot de
Description:
------------
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:
---------------
<?php
$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
fclose($fp);
echo "file written<hr />\n";
show_source("./file.php");
?>

Expected result:
----------------
The expected content of the file "./file.php" should be the following:
<?php
/*
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:
<?php

/*

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-05 03:27 UTC] wez@php.net
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] wez@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 15:01:32 2024 UTC