diff --git a/Zend/Optimizer/zend_dump.c b/Zend/Optimizer/zend_dump.c index bc697ba8ba9e..9eaca19f18f5 100644 --- a/Zend/Optimizer/zend_dump.c +++ b/Zend/Optimizer/zend_dump.c @@ -23,6 +23,7 @@ #include "zend_func_info.h" #include "zend_call_graph.h" #include "zend_dump.h" +#include "ext/standard/php_string.h" void zend_dump_ht(HashTable *ht) { @@ -65,8 +66,12 @@ void zend_dump_const(const zval *zv) case IS_DOUBLE: fprintf(stderr, " float(%g)", Z_DVAL_P(zv)); break; - case IS_STRING: - fprintf(stderr, " string(\"%s\")", Z_STRVAL_P(zv)); + case IS_STRING:; + zend_string *escaped_string = php_addcslashes(Z_STR_P(zv), "\"\\", 2); + + fprintf(stderr, " string(\"%s\")", ZSTR_VAL(escaped_string)); + + zend_string_release(escaped_string); break; case IS_ARRAY: fprintf(stderr, " array(...)"); diff --git a/sapi/phpdbg/tests/print_001.phpt b/sapi/phpdbg/tests/print_001.phpt index c25c5178fef4..a981cb0001f6 100644 --- a/sapi/phpdbg/tests/print_001.phpt +++ b/sapi/phpdbg/tests/print_001.phpt @@ -29,7 +29,7 @@ Foo\Bar::Foo: ; (lines=5, args=1, vars=1, tmps=1) ; %s:5-7 L0005 0000 CV0($bar) = RECV 1 -L0006 0001 INIT_NS_FCALL_BY_NAME 1 string("Foo\var_dump") +L0006 0001 INIT_NS_FCALL_BY_NAME 1 string("Foo\\var_dump") L0006 0002 SEND_VAR_EX CV0($bar) 1 L0006 0003 DO_FCALL L0007 0004 RETURN null @@ -44,10 +44,10 @@ prompt> [Context %s (9 ops)] $_main: ; (lines=9, args=0, vars=0, tmps=4) ; %s:1-21 -L0018 0000 V0 = NEW 0 string("Foo\Bar") +L0018 0000 V0 = NEW 0 string("Foo\\Bar") L0018 0001 DO_FCALL L0018 0002 INIT_METHOD_CALL 1 V0 string("Foo") -L0018 0003 SEND_VAL_EX string("test") 1 +L0018 0003 SEND_VAL_EX string("test \"quotes\"") 1 L0018 0004 DO_FCALL L0019 0005 INIT_FCALL %d %d string("foo") L0019 0006 SEND_VAL string("test") 1 @@ -72,6 +72,6 @@ namespace { var_dump(strrev($baz)); } - (new \Foo\Bar)->Foo("test"); + (new \Foo\Bar)->Foo('test "quotes"'); foo("test"); }