How can I make/patch php source (c code) to read an array from php.ini?

328 views Asked by At

I'm experienced with php but I'm a novice to the php source and php extensions. I want to extend php so that it randomly chooses an upload_tmp_dir from an array, rather than one fixed dir.

It doesn't look like php and the ini-file reading code has any natural ability to parse arrays in the ini file.

Is there any existing code or extension (either in the tree or outside it) that allows for mapping an ini-defined array to a global array val in php?

Otherwise I guess I'll introduce ini vals like "num_upload_dirs" and then "upload_tmp_dir_1" and "upload_tmp_dir_2" etc. and then explicitly check for all vals.

OR write the line-parsing and global-array-creating routines myself into the ini-file reader. Neither are very appealing. Any other suggestions?

2

There are 2 answers

2
Byron Whitlock On BEST ANSWER

The ini file format doesn't support arrays.

You will be best served by doing uplaod_tmp_dir_1 etc. You get no benefit from using array syntax.

It is actually fewer bytes if you think about it. ;)

2
KingCrunch On

PHP supports arrays in ini files by default. There is no need to patch anything

The ini

key[] = value1
key[] = value2

with this php

var_dump(parse_ini_file('my.ini'));

returns

array(1) {
  ["key"]=>
  array(2) {
    [0]=>
    string(6) "value1"
    [1]=>
    string(6) "value2"
  }
}