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 7624879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:05:14+00:00 2026-05-31T05:05:14+00:00

I have two functions function c( &$x ) { $x = 25; echo ‘c

  • 0

I have two functions

function c( &$x )
{
    $x = 25;
    echo 'c is called, x = ' . $x . PHP_EOL;
}

function b()
{
    echo 'b is called'. PHP_EOL;
    return 5;
}

Then I write the following code which as I expect should put result of b() to $o, then pass $o by reference to c() where it is set to the new value. it works ok:

$o=b();
c( $o );
echo 'o is '.$o;

the output is as expected:

b is called
c is called, x = 25
o is 25

But if I try to assign value of $o in function call like this:

c( $o = b() );
echo 'o is '.$o;

I get weird output

b is called
c is called, x = 25
o is 5

the order of function calls is still the same but why $o is not changed in spite of it was passed by reference? Does PHP compulsorily passes argument by value if it is assigned in function call? If yes, since what version had this been working that way? According to this comment: http://www.php.net/manual/en/functions.arguments.php#71198 in 2006 it worked differently. My version is 5.3.6

  • 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-05-31T05:05:15+00:00Added an answer on May 31, 2026 at 5:05 am

    This is a limitation of the Zend engine that I have come across before, particularly when using socket_select()/stream_select(), which both require the “array of resources” arguments to be passed by reference. It would be nice to be able to assign the values of the variables to be passed by reference in one line, but it is not (currently) possible to do it.

    I have seen it mentioned before (although right now I can’t find where, (It was here) and it may not have been authoritative anyway) that any expression in PHP evaluates to the right-hand side of the expression. By which I mean:

    $a = 1;
    $b = 2;
    echo $a = $b;
    

    This will echo 2, because the expression that was passed the echo statement evaluates the right-hand side of the expression $b, which is 2.

    When passing the result of the expression to a function, such as c( $o = b() ); where you are passing the result of $o = b(); to the function c(), it is my understanding (although I could be wrong) that the result of the expression is passed into the function and the function is executed, before a zval is created and assigned to hold $o, behaviour that was designed to reduce memory consumption and speed up internal processing when functions are nested in this way. This means that you have not actually passed the variable by reference, you have simply passed in the value that resulted from b() – the right-hand side of the expression – which cannot be modified by reference since it does not have a variable container.

    Indeed, if you turn on E_STRICT messages, you will see the following error:

    Strict Standards: Only variables should be passed by reference in …

    …so this behaviour is in fact “by design”.

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

Sidebar

Related Questions

Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
I have two Python functions, both of which take variable arguments in their function
I have these two functions (with Point2D & LineVector (has 2 Point2D member variables)
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
Suppose I have two functions which look like this: public static void myFunction1(int a,
Say I have the following two Bash scripts: Version #1: #!/bin/bash function bar {
Hi I am trying to return two variables from a function using the following
we have two class A & B: class A{ var $settings; function getinfo(){ $settings['domain']=mydomain;
I have two files the one which hosts my actual contact form and then

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.