[php-src] Issue #15871: phpinfo()
| From: | EmadAlmahdi | Date: | Fri, 13 Sep 2024 07:45:22 +0000 |
| Subject: | [php-src] Issue #15871: phpinfo() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247773@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15871
Author: EmadAlmahdi
### Description
# Bug Report:
phpinfo() Accepts Any Integer Value as Parameter
**Issue Summary:**
The phpinfo() function in PHP accepts any integer as a parameter, even though it is
supposed to only accept predefined constants as flags. This allows invalid flag values (e.g.,
phpinfo(9999);) to be passed without throwing any error or warning.
**Expected Behavior:**
The phpinfo() function should validate the parameter to ensure that only valid flags
(constants like INFO_GENERAL, INFO_CREDITS, etc.) are passed. Passing an
invalid flag should throw an error (e.g., ValueError) or trigger a warning.
Additionally, an enum could be used to ensure better handling and readability of these flags.
**Current Behavior:**
Currently, calling phpinfo() with any arbitrary integer (e.g.,
phpinfo(9999);) does not produce an error and still generates output, which could lead
to unexpected behavior.
**Steps to Reproduce:**
1. Call phpinfo(9999); or any invalid integer.
2. Observe that no error is thrown, and the function continues to execute.
```php
// Example of unexpected behavior:
phpinfo(9999);
```
**Suggested Fixes:**
- Implement strict validation to check if the passed parameter is a valid constant (or combination
of constants).
- Consider throwing a ValueError or issuing a warning if an invalid flag is passed.
- Introduce an enum or another stricter typing system to define the allowed constants for better
code clarity and maintainability.
**Flags Reference:**
```php
INFO_GENERAL => 1
INFO_CREDITS => 2
INFO_CONFIGURATION=> 4
INFO_MODULES => 8
INFO_ENVIRONMENT => 16
INFO_VARIABLES => 32
INFO_LICENSE => 64
INFO_ALL => -1
```
[Link to phpinfo() documentation](https://www.php.net/manual/en/function.phpinfo.php)
### PHP Version
PHP 8.3.11
### Operating System
Windows 11