|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63784 var_export() produces EOL symbols irregardless of target OS
Submitted: 2012-12-16 23:25 UTC Modified: 2018-05-14 00:27 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: hayk at mail dot ru Assigned: mattficken (profile)
Status: Closed Package: *General Issues
PHP Version: 7.2.2 OS: Windows
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: hayk at mail dot ru
New email:
PHP Version: OS:


 [2012-12-16 23:25 UTC] hayk at mail dot ru
var_export() produces EOL symbols irregardless of target OS. It's always "\n" even on Windows.

Test script:
	$a = array('a' => 1);
	echo var_export($a, true);
	echo strlen(var_export($a, true));

Expected result:
array (
  'a' => 1,

Actual result:
array (
  'a' => 1,


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-23 18:36 UTC]
Actually it is not only var_export(), var_dump() also uses hardcoded LF.
 [2018-03-13 01:09 UTC]
-Operating System: Windows XP +Operating System: Windows -PHP Version: 5.4.9 +PHP Version: 7.2.2
 [2018-03-13 01:09 UTC]
I can repro this on 7.2.2.

var_export() returns \n (10) before the ) character.

The doc for var_export() doesn't specify a \n or \r\n behavior. The doc does specify var_export() should return executable PHP code. Except for Windows Notepad, text editors, IDEs, etc... shouldn't have a problem with this. They can automatically handle both \r\n and \n in same document. So the code var_export() returns can be edited and executed in text editor, IDE, etc...

On Windows 10, the command prompt does handle \n as if it was \r\n. PHP_EOL on Windows does return \r\n to avoid causing problems for terminal emulation.

In userland, var_export() output is often not (only) dumped to terminal but may be used with string parsing, persistence, etc...  Switching to \r\n, because it would add an additional byte/char could break that. Or at least cause a slight performance problem.

It may technically be a bug. But given userland code and that Windows command prompt and text editors can handle \n instead of \r\n, I think this should be reclassified as a "Won't fix".


A more clear repro script:
	$a = array('a' => 1);
	echo var_export($a, true);
	echo strlen(var_export($a, true));
	$b = var_export($a, true);
	echo $b;
	echo strlen($b);
	function ord_array($str) {
		$ords = array();
		for($i = 0; $i < strlen($str); $i++){       
			$s2 = substr($str,$i,1);
			$ords[] = ord($s2);

	echo PHP_EOL;

	echo var_dump(ord_array($b));
 [2018-05-14 00:27 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: mattficken
 [2018-05-14 00:27 UTC]
see previous comment
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun May 19 12:01:26 2019 UTC