fix(stub): 修复heredoc/nowdoc字符串生成非法C++的问题 #36
Merged
韩天峰
merged 5 commits from stub-fix-heredoc-nowdoc-illegal-cpp into master 1 month ago
3 changed files with 90 additions and 9 deletions
@ -0,0 +1,23 @@ |
|||||||
|
--TEST-- |
||||||
|
class constants with heredoc and nowdoc syntax |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
class Test |
||||||
|
{ |
||||||
|
const VALUE1 = <<<ABC |
||||||
|
quote " slash \\ nul \0 tab \t ?? |
||||||
|
ABC; |
||||||
|
const VALUE2 = <<<'DEF' |
||||||
|
$value ?? "quoted" \n \path |
||||||
|
DEF; |
||||||
|
} |
||||||
|
|
||||||
|
function main() |
||||||
|
{ |
||||||
|
var_dump(bin2hex(Test::VALUE1), bin2hex(Test::VALUE2)); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(60) "71756f7465202220736c617368205c206e756c2000207461622009203f3f" |
||||||
|
string(54) "2476616c7565203f3f202271756f74656422205c6e205c70617468" |
||||||
@ -0,0 +1,51 @@ |
|||||||
|
--TEST-- |
||||||
|
global constants, property defaults and parameter defaults with heredoc/nowdoc syntax |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
const G_HEREDOC = <<<ABC |
||||||
|
abc |
||||||
|
ABC; |
||||||
|
const G_NOWDOC = <<<'DEF' |
||||||
|
def |
||||||
|
DEF; |
||||||
|
|
||||||
|
class WithProp |
||||||
|
{ |
||||||
|
public string $p = <<<ABC |
||||||
|
xyz |
||||||
|
ABC; |
||||||
|
} |
||||||
|
|
||||||
|
function with_default(string $x = <<<'ABC' |
||||||
|
$value ?? "quoted" \n \path |
||||||
|
ABC): string { |
||||||
|
return $x; |
||||||
|
} |
||||||
|
|
||||||
|
function with_binary_default(string $x = <<<ABC |
||||||
|
A\0B |
||||||
|
ABC): string { |
||||||
|
return $x; |
||||||
|
} |
||||||
|
|
||||||
|
function main() |
||||||
|
{ |
||||||
|
var_dump(G_HEREDOC, G_NOWDOC); |
||||||
|
$o = new WithProp(); |
||||||
|
var_dump($o->p); |
||||||
|
var_dump(bin2hex(with_default()), bin2hex(with_binary_default())); |
||||||
|
|
||||||
|
$default = (new ReflectionFunction('with_default'))->getParameters()[0]->getDefaultValue(); |
||||||
|
$binaryDefault = (new ReflectionFunction('with_binary_default'))->getParameters()[0]->getDefaultValue(); |
||||||
|
var_dump(bin2hex($default), bin2hex($binaryDefault)); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(3) "abc" |
||||||
|
string(3) "def" |
||||||
|
string(3) "xyz" |
||||||
|
string(54) "2476616c7565203f3f202271756f74656422205c6e205c70617468" |
||||||
|
string(6) "410042" |
||||||
|
string(54) "2476616c7565203f3f202271756f74656422205c6e205c70617468" |
||||||
|
string(6) "410042" |
||||||
Loading…
Reference in new issue