Skip to content

parse_ini_file parse_ini_string bug when when INI_SCANNER_TYPED #11010

Closed

Description

@GajowyJ

Description

The following code:

<?php
$txt = "variable = -00 20 30";
$ret=parse_ini_string($txt,FALSE,INI_SCANNER_TYPED);
var_dump($ret['variable']);

Resulted in this output:

string(7) "0 20 30"

But I expected this output instead:

string(9) "-00 20 30"

or

int(0)

PHP Version

PHP 8.1.17

Operating System

Windows 10

Activity

  1. iluuu1994 commented on Apr 4, 2023

    @iluuu1994
    Member

    The INI scanner converts each token (word) independently. If it is convertible (analogous to is_numeric in PHP) it will be, no matter where after = it appears. https://3v4l.org/0BjuD We might want to try converting the values only in the parser when they appear as standalone values (i.e. when they aren't part of some other expression). I'll give that a shot.

  2. GajowyJ commented on Apr 21, 2023

    @GajowyJ
    Author

    @iluuu1994
    Nothing has changed in PHP v 8.1.18. The issue still exists. Shouldn't the ticket be reopened?

  3. damianwadley commented on Apr 21, 2023

    @damianwadley
    Member

    @GajowyJ The fix has only been added to master, which means as things are now it will only be present in the next series of PHP (probably 8.3).

    @iluuu1994 Is that intentional?

  4. iluuu1994 commented on Apr 21, 2023

    @iluuu1994
    Member

    This was indeed intentional because the changes were non-trivial and affect all of ini parsing. Sorry @GajowyJ, my communication was clearly inadequate here.

  5. iluuu1994 commented on Apr 21, 2023

    @iluuu1994
    Member

    @GajowyJ The way you can avoid this at the moment is to wrap the value in double quotes (""). https://3v4l.org/QSBA3

  6. GajowyJ commented on Apr 21, 2023

    @GajowyJ
    Author

    @iluuu1994 @damianwadley
    Thank you for the clarification.

  7. added a commit that references this issue on Jul 19, 2024
    86ffde3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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