Skip to content

parse_str - replacing dot and space with underscore in keys #8639

Closed
@otsch

Description

@otsch

Description

I just remembered this behavior when using parse_str(), that dots and spaces in query string keys are replaced with underscore, for the reason that those aren't allowed in PHP variable names. From PHP 8 on the second argument $result is mandatory, so I think it now doesn't create variables in any case, right? So to me, replacing those characters in the resulting array keys, seems like a leftover that could be removed?

Example:

<?php

parse_str('foo.bar =baz', $array);

var_dump($array);

Currently results in:

array(1) {
  ["foo_bar_"]=>
  string(3) "baz"
}

Maybe better?

array(1) {
  ["foo.bar "]=>
  string(3) "baz"
}

PHP Version

PHP 8

Operating System

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