When building tools that inspect PHP code, ReflectionExtension::getINIEntries() helps answer a focused question: lists php.ini directives registered by the extension with their current values.
Reflection is useful in framework tooling, dependency injection, testing, code inspection and debugging.
What Is ReflectionExtension::getINIEntries()?
Lists php.ini directives registered by the extension with their current values.
Its method signature is:
public function getINIEntries(): array
This method has no required arguments.
Return value: array
Example 1: Inspect a loaded extension
Start with a self-contained PHP declaration and inspect the method result.
<?php
declare(strict_types=1);
$extensionReflection = new ReflectionExtension("json");
$result = $extensionReflection->getINIEntries();
echo count($result);
Output:
0
Explanation: Lists php.ini directives registered by the extension with their current values.
Example 2: Compare extension metadata
Next, change the reflected declaration or parameter to observe a related situation.
<?php
declare(strict_types=1);
$extensionReflection = new ReflectionExtension("date");
$result = $extensionReflection->getINIEntries();
echo count($result);
// Check the returned value type before using the result.
echo "\nResult type: " . get_debug_type($result);
Output:
5
Result type: array
Explanation: Configuration can vary between CLI, FPM and other SAPIs.
Practical Example: Use extension information for diagnostics
This final case shows how the same API can be used when inspecting application definitions.
<?php
declare(strict_types=1);
$extensionReflection = new ReflectionExtension("standard");
$result = $extensionReflection->getINIEntries();
echo count($result);
// Use the reflection result in a simple decision.
if (is_bool($result)) {
echo "\nStatus: " . ($result ? "yes" : "no");
} elseif (is_array($result)) {
echo "\nEntries: " . count($result);
} elseif ($result === null) {
echo "\nNo value returned";
} else {
echo "\nReflection result available";
}
Output:
14
Entries: 14
Explanation: ini_get_all can inspect directive values beyond a single extension.
Important Behavior and Edge Cases
- Configuration can vary between CLI, FPM and other SAPIs.
- ini_get_all can inspect directive values beyond a single extension.
- Reflection describes declarations and runtime state; requesting metadata does not automatically validate or sanitize application input.
Comparison With Related Approaches
| Approach | When to Use It |
|---|---|
ReflectionExtension::getINIEntries() | Lists php.ini directives registered by the extension with their current values. |
Related API | ini_get_all can inspect directive values beyond a single extension. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring this condition: Configuration can vary between CLI, FPM and other SAPIs. | Handle the specific limitation: Configuration can vary between CLI, FPM and other SAPIs. |
| Confusing this method with Related API | ini_get_all can inspect directive values beyond a single extension. |
Key Takeaways
- Lists php.ini directives registered by the extension with their current values.
- Configuration can vary between CLI, FPM and other SAPIs.
- ini_get_all can inspect directive values beyond a single extension.
Use ReflectionExtension::getINIEntries() when you need the precise metadata or behavior demonstrated above. Keep the target declaration and relevant PHP version in mind when adapting the examples.