Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of special characters(^ and $) in INI setting for type string won't work as expected #12470

Closed
HeenaBansal2009 opened this issue Oct 18, 2023 · 1 comment

Comments

@HeenaBansal2009
Copy link

Description

The ini setting doesn't work as expected when setting has regex expressions
My customized ini file has string with regular expressions like below
Case 1:
Ini setting value :
abc=[Tt][Oo][Kk][Ee][Nn].,^[Qq],one, two

php -I |grep abc shows
myextension.abc=> 0 => 0

But I expected this output instead:
php -I |grep abc shows
myextension.abc=> [Tt][Oo][Kk][Ee][Nn].,^[Qq],one, two =>[Tt][Oo][Kk][Ee][Nn].,^[Qq],one, two

Case 2:
Ini setting value :
abc=[Tt][Oo][Kk][Ee][Nn].

php -I |grep abc shows
myextension.abc=> [Tt][Oo][Kk][Ee][Nn].=>[Tt][Oo][Kk][Ee][Nn].

Case 3:
Ini setting value :
abc=.^[Qq]$
php -I |grep abc shows
PHP: syntax error, unexpected '=' myextension.ini on line 9
myextension.abc=> 0 =>0

Is there any limitation with regex expressions in php ini settings. Though It seems like carrot ^ and $ dollar sign doesn't seems to work with string ini setting.

PHP Version

PHP 8.1

Operating System

No response

@damianwadley
Copy link
Member

PHP understands some special characters in INI files. ^ is one of them, and acts as an XOR operator; it's meant to be used with bitmask fields like error_reporting. $ is another, in that can be used for interpolating variables and so gets its own treatment during parsing.

If you want special characters like those then the value needs to be quoted.

abc="[Tt][Oo][Kk][Ee][Nn].,^[Qq],one, two"

If you need a " itself, escape it with a backslash.

https://www.php.net/manual/en/configuration.file.php
https://www.php.net/manual/en/function.parse-ini-file.php (which is what PHP uses internally too)

@damianwadley damianwadley closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants