Skip to content

25: Show Function Arguments in PHP Errors

Compare the same warning with argument display turned off and on. This setting can help you identify the inputs that reached a failing function.

  • PHP 8.6 CLI. Confirm the version with php --version.
  • Review the previous chapter if you’re following the series in order.

Allow about 10 minutes for the walkthrough and exercise.

A runnable error-include-args.php example.

Run the following from the root of the Code with PHP repository.

Terminal window
php code/php-8-6/25-error-include-args/error-include-args.php
error-include-args.php
<?php
declare(strict_types=1);
set_error_handler(static function (int $level, string $message): bool {
echo $message, PHP_EOL;
return true;
}, E_WARNING);
try {
foreach (['0', '1'] as $enabled) {
ini_set('error_include_args', $enabled);
echo "Setting $enabled: ";
unlink('php://memory');
}
} finally {
restore_error_handler();
}
Setting 0: unlink(): PHP does not allow unlinking
Setting 1: unlink('php://memory'): PHP does not allow unlinking

The php://memory wrapper rejects the unlink operation, so PHP emits a warning without touching a disk file. The custom error handler prints the complete warning message. With the INI setting enabled, PHP inserts the supplied argument into the function signature. It uses the engine’s argument formatting, including truncation and sensitive-parameter redaction.

Run the script again with php -d zend.exception_string_param_max_len=6. Check that the enabled warning shows 'php://...'.

Continue with Reverse Text by Grapheme Cluster.