tysonandre / var_representation_polyfill
var_representation 的 Polyfill:以修复 var_export 的不足的方式将变量转换为字符串
0.1.3
2022-08-31 12:59 UTC
Requires
- php: ^7.2.0|^8.0.0
- ext-tokenizer: *
Requires (Dev)
- phan/phan: ^5.4.1
- phpunit/phpunit: ^8.5.0
Suggests
- ext-var_representation: For best performance
Provides
This package is auto-updated.
Last update: 2024-08-29 06:07:19 UTC
README
var_representation_polyfill 是 https://pecl.php.net/var_representation 的 Polyfill
这提供了 var_representation(mixed $value, int $flags = 0): string
函数的 Polyfill,该函数以修复 var_export()
的不足的方式将变量转换为字符串
有关详细信息,请参阅 var_representation PECL 文档
安装
composer require tysonandre/var_representation_polyfill
用法
// uses short arrays, and omits array keys if array_is_list() would be true php > echo var_representation(['a','b']); [ 'a', 'b', ] // can dump everything on one line. php > echo var_representation(['a', 'b', 'c'], VAR_REPRESENTATION_SINGLE_LINE); ['a', 'b', 'c'] php > echo var_representation("uses double quotes: \$\"'\\\n"); "uses double quotes: \$\"'\\\n" // Can disable the escaping of control characters as of polyfill version 0.1.0 // (e.g. if the return value needs to be escaped again) php > echo var_representation("has\nnewlines", VAR_REPRESENTATION_UNESCAPED); 'has newlines' php > echo json_encode("uses single quotes:\0\r\n\$\"'\\"); "uses single quotes:\u0000\r\n$\"'\\" php > echo json_encode(var_representation("uses single quotes:\0\r\n\$\"'\\", VAR_REPRESENTATION_UNESCAPED)); "'uses single quotes:\u0000\r\n$\"\\'\\\\'"