Problem/Motivation

There are many issue reports of receiving a message of the form
Deprecated function: Call-time pass-by-reference has been deprecated in function_name() (line nnnn of sourcefile).
... but the message does not come from the source line mentioned. The message is produced when the PHP is parsed during require/include(_once) processing.
In _drupal_error_handler_real() the call to _drupal_log_error() reports the source line and file information from _drupal_get_last_caller().
So we get the message:

Deprecated function: Call-time pass-by-reference has been deprecated in oik_settings_form() (line 161 of C:\...\sites\all\modules\_custom\oik\oik.module).

but the code at line 161 was

  require_once( "bobbformd.inc" );

The actual clue to the problem is passed in the data returned from debug_backtrace() for drupal_error_handler (and drupal_error_handler).

C:\...\includes\bootstrap.inc(2207:0)   _drupal_error_handler_real 3 Array
(
    [0] => 8192
    [1] => Call-time pass-by-reference has been deprecated
    [2] => C:\...\sites\all\modules\_custom\oik\bobbformd.inc
    [3] => 122
    [4] => Array
        (
        )
)

C:\...\sites\all\modules\_custom\oik\oik.module(161:0)   _drupal_error_handler 4 Array
(
    [0] => 8192
    [1] => Call-time pass-by-reference has been deprecated
    [2] => C:\...\sites\all\modules\_custom\oik\bobbformd.inc
    [3] => 122
    [4] => Array
        (
        )
)

C:\...\sites\all\modules\_custom\oik\oik.module(161:0)   oik_settings_form 5 
(0:0)   oik_settings_form 6 Array
(
    [0] => Array
        (

where line 122 of bobbformd.inc was

function actpbrc( &$byref) {  actpbra( &$byref ); }

The "error" being the & on the call to actpbra().

So to aid problem determination we need to provide a bit more information from the debug_backtrace data in the error log.

Proposed resolution

Rather than change _drupal_get_last_caller() I realised that the "missing" information was being passed to _drupal_error_handler_real() in the parameters. So a simple fix is to issue TWO messages when the $filename and $line passed don't match $caller['file'] or $caller['line'] returned from _drupal_get_last_caller().
Add this code before the current call to _drupal_log_error().

    if ( $caller['file'] != $filename || $caller['line'] != $line ) {

      _drupal_log_error(array(
        '%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error',
        // The standard PHP error handler considers that the error messages
        // are HTML. We mimick this behavior here.
        '!message' => filter_xss_admin($message),
        
        '%function' => "unknown",
        '%file' => $filename,
        '%line' => $line,
        'severity_level' => $severity_level,
      ), $error_level == E_RECOVERABLE_ERROR);
    }

The first message shows where the error actually occurred and the second shows most recent function call.

Deprecated function: Call-time pass-by-reference has been deprecated in unknown (line 122 of C:\...\sites\all\modules\_custom\oik\bobbformd.inc).
Deprecated function: Call-time pass-by-reference has been deprecated in oik_settings_form() (line 161 of C:\...\sites\all\modules\_custom\oik\oik.module).

Remaining tasks

It would probably be nicer to make it clear that the additional information provided by the second message is to help locate the actual message.

User interface changes

N/A?

API changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

SocialNicheGuru’s picture

Version: 7.12 » 7.14

the file to patch is includes/error.inc

and this works soooo very well.

Thank you.

Because Drupal 7 now makes recoverable errors, fatal, I could not run crush. this is a great addition.

Fabianx’s picture

Status: Active » Reviewed & tested by the community

Great patch!

Does the job ...

SocialNicheGuru’s picture

how can we get this into core?

oriol_e9g’s picture

Status: Reviewed & tested by the community » Needs work

You need to create a patch

marcingy’s picture

Version: 7.14 » 8.x-dev

And it needs to start life in d8.

Fabianx’s picture

Status: Needs work » Needs review
FileSize
1.52 KB

I just stumbled upon that again.

Here is a first patch for that in 8.x.

Edit:

Yes! - It also applies to 7.x still. Fun!

pingers’s picture

+++ b/core/includes/errors.inc
@@ -63,6 +63,20 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c
 
+    // Catch errors created via require / drupal_load

Missing period. "Catch errors created via require and drupal_load." is better I think.

Created a test module with a call to a function using a reference:

function test_init() {
  $a = 1;
  test_it(&$a);
}
function test_it(&$a) {}

Before patch:
Deprecated function: Call-time pass-by-reference has been deprecated in drupal_load() (line 1157 of /var/www/drupal/core/includes/bootstrap.inc).

After patch:
Deprecated function: Call-time pass-by-reference has been deprecated in unknown (line 6 of /var/www/drupal/sites/all/modules/test/test.module).

RTBC if green. I don't think a minor string change precludes me from rtbc'ing :)

Fabianx’s picture

Issue tags: +Needs backport to D7

Ultimately this needs a backport to D7.

pingers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs backport to D7
FileSize
1.08 KB

I'm a dummy. Function names (require and drupal_load) need (). Re-rolled.

Fabianx’s picture

Issue tags: +Needs backport to D7

xpost

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Checking. Is it possible to add test coverage for this?

Fabianx’s picture

Assigned: Unassigned » Fabianx

Status: Needs review » Needs work
mgifford’s picture

Assigned: Fabianx » Unassigned
Issue tags: +Needs tests

This still a concern in D8? Unassigned issue too.

Fabianx’s picture

Assigned: Unassigned » Fabianx

Yes, that would still be useful for D8.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

There has been no activity here for 8 years. The function in the patch was removed from core in 2011, 12 years ago. I am not able to figure what might still need to be done.

Is there anything still to do here?

I am setting the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!

Kristen Pol’s picture

Assigned: Fabianx » Unassigned
Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

As part of the Bug Smash Initiative, we are triaging issues that are marked "Postponed (maintainer needs more info)". This issue was marked "Postponed (maintainer needs more info)" 3 months ago.

Since we need additional information for this issue to progress, I'm marking the issue "Closed (cannot reproduce)". If anyone can provide complete steps to reproduce the issue (starting from "Install Drupal core"), document those steps in the issue summary and set the issue status back to "Active" [or "Needs Work" if it has a patch, etc.].

Thanks!