php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25874 var_export does not output valid code
Submitted: 2003-10-14 22:21 UTC Modified: 2013-08-25 21:04 UTC
From: fire at firepages dot com dot au Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.3.3 OS: XP
Private report: No CVE-ID: None
 [2003-10-14 22:21 UTC] fire at firepages dot com dot au
Description:
------------
output from var_export($var,true) has trailing comma so you have to strip that manually before utilising the returned string.

the manual example shows this behaviour so perhaps its a feature ?

Reproduce code:
---------------
$yaks = array( 'dfdf'=>'a' , 'b' , 'c' , 'd' ) ;
echo '$llama = ' . var_export( $yaks , true ) . ' ;' ;

Expected result:
----------------
$llama = array ( 'dfdf' => 'a', 0 => 'b', 1 => 'c', 2 => 'd' ) ;

Actual result:
--------------
$llama = array ( 'dfdf' => 'a', 0 => 'b', 1 => 'c', 2 => 'd', ) ;

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-14 23:04 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The trailing comma while unusual is perfectly valid and the code evaluates correctly.
 [2013-08-25 18:52 UTC] paulwolbers at home dot nl
But why is the comma there? I don't want there because it looks like something's wrong (even if it's correct behaviour)

by the way: you have to check your emailvalidator ... it says my emailaddress is not valid (so now i used another one)
 [2013-08-25 20:58 UTC] yohgaki@php.net
Check documentation. Trailing comma is allowed in PHP.
Comma is there for simplicity. Try to write your own, then you'll see.

It's easy to write code, easy to add additional element.
 [2013-08-25 21:04 UTC] yohgaki@php.net
> by the way: you have to check your emailvalidator ... it says my emailaddress 
is not valid (so now i used another one)

I have no idea what you're referring.
Create new report if it's new, or add comment to appropriate report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC