Jump to content

Debug_backtrace notice-what’s causing it in my code?

Go to solution Solved by dwest100,

Recommended Posts

I have this function which works except it throws a Notice regarding the 3rd line of the function. The Notice reads "Only variables should be passed by reference..." What am I doing wrong in that 3rd line—$caller = next(debug_backtrace()) [‘function’]; ?
Thanks for any assistance!

//Sends email to site admin if email testing services fail.
//Only occurs if both primary and secondary services have failed.
//Calls no other function.
//Called by test_email function.

function email_admin($email){
    global $full_site_url;//used in links.
    global $site_title;//used in confirmation messages.
    $caller = next(debug_backtrace())['function']; //assigns calling function name to $caller.
    if ($caller == 'alt_test_email'){
        //used in email message to provide links for checking services.
        $primary_service = 'http://www.quickemailverification.com';//used in email message.
        $secondary_service = 'http://www.neverbounce.com';//used in email message.

        $to = get_bloginfo('admin_email');
        $message = 'Both email testing services have failed. Go to ' . $primary_service . ' and ' . $secondary_service . '.';
        dw_send_email($to, $subject, $message);//call email sending function.
    if ($caller == 'unsubscribe'){
        $to = get_bloginfo('admin_email');
        $subject = $site_title . " unsubscribe";
        $message = $email . " has unsubscribed.";
        dw_send_email($to, $subject, $message);//call email sending function.
    if ($caller == 'subscribe_form_display'){
        $to = get_bloginfo('admin_email');
        $subject = "New " . $site_title . " subscriber";
        $message = $email . " has subscribed to " . $site_title . ".";
        dw_send_email($to, $subject, $message);//call email sending function.


Link to post
Share on other sites

next() operates on array variables. You are trying to give it an array that is not a variable.

It's trying to get the second item in that backtrace array. Use regular array offset [ ] notation instead - yes, you can do it right after a function call.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.