Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Conversation

janduy
Copy link

@janduy janduy commented Mar 16, 2025

Summary

This PR removes the $context parameter from the phpagi_error_handler() function to resolve an "ArgumentCountError" that occurs in PHP 8.1 when using set_error_handler().

Problem

In PHP 8.1, set_error_handler() only passes 4 arguments by default:

  • $level
  • $message
  • $file
  • $line

However, phpagi_error_handler() is currently defined with 5 parameters:

function phpagi_error_handler($level, $message, $file, $line, $context)

Problem

PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function phpagi_error_handler(), 4 passed and exactly 5 expected

Solution

  • The $context parameter is not used anywhere in the function, so it is safe to remove it.
  • This change ensures full compatibility with PHP 8.1 while maintaining the expected behavior.

Changes in This PR

  • Modified phpagi_error_handler() to accept only 4 parameters (removing $context).
  • Updated send_error_email() to align with the new function signature.

Before (causing error in PHP 8.1)

function phpagi_error_handler($level, $message, $file, $line, $context)

After (fixes PHP 8.1 error)

function phpagi_error_handler($level, $message, $file, $line)

Impact

✅ Fixes compatibility issues in PHP 8.1
✅ No change in behavior, as $context was never used
✅ Improves stability for projects using PHP 8.1+

Testing

  • Tested with PHP 8.1.
  • No regression found in error handling functionality.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant