Skip to content

dumpType() not escaping enough for PHPDoc types #11823

@zonuexe

Description

@zonuexe

Feature request

While it would be convenient to copy and paste the type generated by PHPStan\dumpType() into @return, it's not actually consistent with the types accepted by phpstan/phpdoc-parser.

$result = [];
$result['Shall we dance?'] = 'yes';
$result["\0"] = "\000";
$result["\n"] = "\n";
$result["\x09"] = "\x09";
$result["\x7f"] = "\x7f";

assertType('array{\'Shall we dance?\': \'yes\', "\000": "\000", "\n": "\n", "\t": "\t", "\x7f": "\x7f"}', $result);
// Expected type array{'Shall we dance?': 'yes', "\000": "\000", "\n": "\n", "\t": "\t", "\x7f": "\x7f"},
//       actual: array{Shall we dance?: 'yes', : "\000", 
: "\n", 	: "\t", �: ''}

https://phpstan.org/r/9e70bcb7-6b97-4b18-b928-3aacf2552d1b

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions