Skip to content

GlobalState::getIniSettingsAsString() generates code that triggers warnings #5270

@sebastianbergmann

Description

@sebastianbergmann

We have this code (PHPUnit 9.6, PHPUnit 10.0)

$result = '';

foreach (ini_get_all(null, false) as $key => $value) {
    $result .= sprintf(
        '@ini_set(%s, %s);' . "\n",
        self::exportVariable($key),
        self::exportVariable((string) $value)
    );
}

to generate code that when run in a separate process reproduces the PHP configuration in the parent process.

This can, for instance, lead to

@ini_set('mbstring.internal_encoding', '');

being run, which triggers a warning because mbstring.internal_encoding is deprecated.

We should avoid generating ini_set() calls for values that are not configured in the parent process.

It is unclear whether $value === null can be safely used to detect whether a value is configured or not.

As the error suppression operator @ is used, this should only ever be a problem when a custom error handler does not honor the fact that such a warning should be ignored.

Metadata

Metadata

Labels

feature/process-isolationIssues related to running tests in separate PHP processesfeature/test-runnerCLI test runnertype/bugSomething is brokenversion/10Something affects PHPUnit 10version/9Something affects PHPUnit 9

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions