PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » PHP » PHP_Compat » Bug #3572

Use of addslashes() adds too much backslashes

Details

Submitted2005-02-24 09:59 UTC
Frombluem at gmx dot de
Assignedaidan
StatusClosed
PackagePHP_Compat
PHP VersionIrrelevant
OSAny (reprod.: Linux, Mac OS X)
Roadmaps1.6.0a1

Comments

[2005-02-24 09:59 UTC] bluem at gmx dot de

Description:
------------
This bug affects the implementation of var_export() in
the latest PHP_Compat version (4.3.1).

Problem:
Strings are quoted using $stringdelim, but
nevertheless escaping is done with addslashes(). This
results in double quotes being escaped with a backslash,
although no backslash would be necessary.

Solution:
It should suffice to exchange the two occurrences of
addslashes() with the following code:
str_replace($stringdelim, '\\'.$stringdelim, $value)

Reproduce code:
---------------
echo "<pre>";
print_r(var_export('Hello "Foo" World'));
echo "</pre>\n";

Expected result:
----------------
'Hello "Foo" World'

Actual result:
--------------
'Hello \"Foo\" World'