Skip to content

How to make the dumper produce guaranteed-valid PHP strings? #568

@phil-s

Description

@phil-s

I think it's CliDumper::dumpString() which is responsible for the likes of these?

>>> '"'
=> """

>>> 'foo
... bar'
=> """
   foo\n
   bar
   """

Neither of those outputs are valid PHP strings, and I would like them to be.

e.g.

>>> '"'
=> "\""

>>> 'foo
... bar'
=> "foo
bar"

That dumpString() method itself seems pretty hard-coded in this respect, and I couldn't see anything in the manual other than the casters pointer; but based on the upstream description I'm not sure that's actually relevant to simple string values?

Objects and resources nested in a PHP variable are "cast" to arrays in the intermediate Data representation. You can customize the array representation for each object/resource by hooking a Caster into this process. The component already includes many casters for base PHP classes and other common classes.

It looks like a bit of a rabbit hole, so I thought I'd ask for directions...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions