Problem/Motivation

It happens when using external libraries that at some point, run the error handler manually (in my case it happens with Symfony, but it could happen with any library playing a bit with error handlers).

Proposed resolution

A very simple solution is make the 5th argument optional providing a default value.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Comments

benjifisher created an issue. See original summary.

benjifisher’s picture

I think I ran into this with Drupal 8, but I am not sure how to reproduce the problem. I noticed #2947291: Missing argument 5 for _drupal_error_handler(), and @catch suggested filing a new issue for Drupal 7, so here it is. I used the text from the Drupal 8 issue for the issue description here.

benjifisher’s picture

Issue tags: +Novice

Looking at the patch that was committed for Drupal 8, I think this issue is appropriate for a novice, so I am adding the appropriate tag.

pounard’s picture

ajaybmishra’s picture

Status: Active » Needs review
StatusFileSize
new2.04 KB

Corrected drupal 7 error handler signature with default values for function parameters, also updated Parameters comment section with "Optional" keyword.

Patch attached.

benjifisher’s picture

Status: Needs review » Needs work

@ajaybmishra25:

Thanks for the patch!

The patch in #2947291: Missing argument 5 for _drupal_error_handler() (the Drupal 8 version of this issue) uses NULL for the default values:

-function _drupal_error_handler($error_level, $message, $filename, $line, $context) {
+function _drupal_error_handler($error_level, $message, $filename = NULL, $line = NULL, $context = NULL) {

I think that is pretty standard in PHP, so that callers know they can set, for example $line = NULL if they want the default value of that variable and need to specify a non-default $context.

Your patch uses three different default values:

-function _drupal_error_handler($error_level, $message, $filename, $line, $context) {
+function _drupal_error_handler($error_level, $message, $filename = NULL, $line = 0, $context = array()) {

Is there any reason you chose not to use NULL as in the version of the patch for Drupal 8?

I am setting the status to "Needs work", but that work could be either an updated patch or a comment explaining why the Drupal 7 version should be different from the Drupal 8 version.

ajaybmishra’s picture

Hello benjifisher,

Thanks for your guidance in right path.

Actually I tried to set default values based on the type of value that parameter expects, so that callers must know what value they must set.

As we have to follow Drupal 8 coding standard, so we must change the default values to NULL, I am updating the patch.

ajaybmishra’s picture

Status: Needs work » Needs review
StatusFileSize
new1.3 KB

Hello benjifisher,

I have updated the patch file with changes suggested, please review.

Status: Needs review » Needs work
ajaybmishra’s picture

Status: Needs work » Needs review
StatusFileSize
new2.08 KB

Hello benjifisher,

Corrected the patch, please review.

Status: Needs review » Needs work
ajaybmishra’s picture

Status: Needs work » Needs review
StatusFileSize
new1.3 KB

Hello,

Corrected the failed patch, please review.

Status: Needs review » Needs work
mr.baileys’s picture

@ajaybmishra25: the most recent patch you provided is against your previous change/patch, not against 7.x-dev, which is why it fails to apply.

ajaybmishra’s picture

Hi mr.baileys,

Thanks for help, yes i am working on it.

singhkiran’s picture

Status: Needs work » Needs review
StatusFileSize
new1.02 KB

As per me , this is the correct way .

msankhala’s picture

Status: Needs review » Needs work
+++ b/includes/bootstrap.inc
@@ -2579,14 +2579,14 @@ function drupal_get_hash_salt() {
- *   An array that points to the active symbol table at the point the error
+ *   (optional) An array that points to the active symbol table at the point the error

Line length increasing 80 characters. As per Drupal API documentation and comment standards:

Lines containing comments (including docblocks) must wrap as close to 80 characters as possible without going over, with a few exceptions (noted in the Tag Reference below).

see https://www.drupal.org/docs/develop/standards/api-documentation-and-comm...

singhkiran’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB

I have fixed coding standard .

Status: Needs review » Needs work

The last submitted patch, 18: Missing-argument-3012167-18.patch, failed testing. View results

msankhala’s picture

Status: Needs work » Needs review

Looks like the issue is with test bot, not with this patch.

msankhala’s picture

Status: Needs review » Reviewed & tested by the community

Tests have passed so I am moving it to RTBC. Looks good to me.

ajaybmishra’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.24 KB

Hello singhkiran,

You missed to correct coding standard in below function, which was added earlier in patch no. 5.

_drupal_error_handler_real

I am correcting this patch, please find the attached patch.

benjifisher’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.04 KB

@ajaybmishra25:

Please use the comment number (the expected number of the comment you are adding) as the last part of the patch filename. Instead of -10.patch for your most recent patch, that would have been -22.patch. Every so often, someone else adds a comment just before you do, and the number may be off, but it makes it easier to match the patches to the corresponding comments.

I see two differences between the patch in #22 and the one in #18:

  1. The patch in #18 updates the doc block, adding "(optional)".
  2. The patch in #22 adds default parameters to _drupal_error_handler_real() as well as to _drupal_error_handler().

As I said in #6, we should avoid unnecessary differences between Drupal 7 and Drupal 8. On both points, the patch in #18 wins. In fact, that patch is almost identical to the patch that was committed to Drupal 8 (from #11, not #9, in #2947291: Missing argument 5 for _drupal_error_handler()). The only differences are the filename (core/includes/bootstrap.php in D8, includes/bootstrap.php in D7) and the change requested in #17.

There is no need to change the parameters to _drupal_error_handler_real(), since it should only be called by _drupal_error_handler(), which already supplies the parameters. I am not sure why you refer to this as a problem with coding standards.

I will re-upload @singhkiran's patch from #18 and restore the status of this issue to RTBC.

mulambo’s picture

#18 seems like a win to me. In D8 it is almost identical (path is different and last doc param has word 'the' on different line).

It also resolves issue with D7 not working on PHP 8, since 5th parameter in error_handler is deprecated since PHP 7.2 (https://www.php.net/manual/en/function.set-error-handler.php) and removed in PHP 8.

mulambo’s picture

Status: Reviewed & tested by the community » Fixed

Fixed in #3200407

benjifisher’s picture

@Mulambo:

Thanks for updating this issue. I think the correct status is Closed (duplicate) instead of Fixed.

I will add credit to #3200407: [PHP8] ArgumentCountError: Too few arguments to function _drupal_error_handler() and friends for some of thepeople who participated on this issue.