php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78361 parse_ini_file converts constants to strings, even with INI_SCANNER_TYPED
Submitted: 2019-08-01 09:37 UTC Modified: 2019-08-01 09:55 UTC
From: mfishe at gmail dot com Assigned:
Status: Verified Package: Unknown/Other Function
PHP Version: Irrelevant OS: Mac, Ubuntu
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mfishe at gmail dot com
New email:
PHP Version: OS:

 

 [2019-08-01 09:37 UTC] mfishe at gmail dot com
Description:
------------
With the following .ini file ...

----------
NUMBER = 1
TEXT = "1"
DEFINED_INTEGER_CONSTANT = FOO
DEFINED_BOOLEAN_CONSTANT = BAR
UNDEFINED_CONSTANT = BAZ
----------

I have tested this behaviour in 7.1.26, 7.3.1 and 7.3.7.


Test script:
---------------
<?php
declare(strict_types=1);
define("FOO", 123);
define("BAR", true);

$ini_file = parse_ini_file(__DIR__ . '/test.ini', false, INI_SCANNER_TYPED);

foreach($ini_file as $key => $value) {
    define($key, $value);
}

var_dump(NUMBER); // => int(1)
var_dump(TEXT); // => string(1) "1"
var_dump(DEFINED_INTEGER_CONSTANT); // => string(3) "123"
var_dump(DEFINED_BOOLEAN_CONSTANT); // => "1"
var_dump(UNDEFINED_CONSTANT); // => "BAZ"

Expected result:
----------------
I expect the third var_dump to output an integer (123) due to the use of INI_SCANNER_TYPED.

Actual result:
--------------
The third var_dump outputs a string ("123").

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-01 09:55 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2019-08-01 09:55 UTC] cmb@php.net
See also <https://3v4l.org/DbEYV>.

Also DEFINED_BOOLEAN_CONSTANT should be TRUE, not "1".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 05 00:01:30 2024 UTC