Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:25:56+00:00 2026-06-12T18:25:56+00:00

While working with Laravel framework, more specific – Form macros, I stumbled upon a

  • 0

While working with Laravel framework, more specific – Form macros, I stumbled upon a weird error.

At first, I thought it’s something wrong with Laravel, but then I took everything out of context:

<?php

// placeholder function that takes variable as reference
$function = function(&$reference)
{
    // append to variable
    $reference = $reference . ':' . __METHOD__;
};

// test with straight call
$variable = 'something';
$function($variable);
echo $variable;


// test with call_user_func(), that gets called in Laravels case
$variable = 'something'; // reset
call_user_func($function, $variable);
echo $variable;

While the first call to $function executes properly, the second try with call_user_func(), produces (excerpt from Codepad):

Warning: Parameter 1 to {closure}() expected to be a reference, value given
PHP Warning: Parameter 1 to {closure}() expected to be a reference, value given

Fiddle: Codepad @ Viper-7

While writing this, I thought about call_user_func_array(): fiddle here, but the same error is produced.

Have I got something wrong about references or is this a bug with PHP?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:25:58+00:00Added an answer on June 12, 2026 at 6:25 pm

    I would call this a bug with PHP, although it’s technically a bug with call_user_func. The documentation does mention this, but perhaps not in a very enlightening way:

    Note that the parameters for call_user_func() are not passed by
    reference.

    It would be perhaps clearer to say that the arguments to call_user_func() are not passed by reference (but note that technically it’s not necessary to say anything at all; this information is also embedded in the function signature).

    In any case, this means is that when call_user_func finally gets to invoking its target callable, the ZVAL (PHP engine internal data structure for all types of values) for the argument being passed is not marked as “being-a-reference”; the closure checks this at runtime and complains because its signature says that the argument must be a reference.

    In PHP < 5.4.0 it is possible to work around this by using call-time pass by reference:

     call_user_func($function, &$variable);
    

    but this produces an E_DEPRECATED warning because call-time pass by reference is a deprecated feature, and will flat out cause a fatal error in PHP 5.4 because the feature has been removed completely.

    Conclusion: there is no good way to use call_user_func in this manner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while working with linq query i'm receiving error System.NullReferenceException: Object reference not set to
While working with annotations I stumbled accross the following piece of code (it's the
While working on HTML, CSS (and more) like changing the code and refreshing the
While working with macros, I have reached the point (I have been trying hard
While working on an existing project I suddenly got the following error when trying
While working with ssh I sometimes write to long string/commands eg. command -param 3
While working on something non-development related, I noticed something interested while on answers.com .
While working on my final project for my AS/400 Course, I encountered this problem
While working with Database records ,displaying them on HTML and storing their ID into
While working a project tonight, I ended up using one .js resource file for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.