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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:05:49+00:00 2026-06-05T12:05:49+00:00

I have a quick question regarding PHP’s return statement. In C++, we’re able to

  • 0

I have a quick question regarding PHP’s return statement. In C++, we’re able to perform the following:

... function body ...
return (foo = bar, biz());

Where the variable bar is assigned to foo before the result of biz() is returned.

Is this possible (or something similar) in PHP? The above statement in PHP results in a parse error. Now, I’m aware that I can simply perform the assignment before the return statement, but this is just a contrived example, and I’m curious as to the feasibility.

Edit: Providing a little more clarification. Here is what I’m basically attempting to do in PHP:

return ($foo = $bar, biz())
    || ($foo = $bar, baz())
    || ($foo = $bar, qux());

foo is a global reference in which biz modifies. If biz returns false, the next segment in the OR statement is tested. Because biz returned false, I need to “reset” the value of foo before executing baz and so on and so forth.

I’m aware that what I’m trying to do here is impure, but I’m just curious is an equivalent (or at least similar thing) is possible in 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-05T12:05:50+00:00Added an answer on June 5, 2026 at 12:05 pm

    No, unfortunately PHP doesn’t actually have a comma operator except in expr1 of a for loop. Everywhere else a comma is just used to separate arguments to a function or language construct.

    You could sort make your own comma operator user function, which just returns the last argument passed into it. Here’s my shot at it:

    function comma(){ return func_get_arg(func_num_args() - 1); }
    

    With this you could use:

    return comma($foo = $bar, biz());
    

    The following complete code outputs Hello:

    <?php
    
    function foo(){
      $bar = 'Hello';
      return comma($foo = $bar, bar($foo));
    }
    
    function bar($foo){
        echo $foo;
    }
    
    foo();
    
    function comma(){ return func_get_arg(func_num_args() - 1); }
    

    Edit

    Your sample code, using the comma function, would look like this:

    return comma($foo = $bar, biz())
        || comma($foo = $bar, baz())
        || comma($foo = $bar, qux());
    

    I honestly can’t recommend using this though. That is why my short answer is “No”.

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

Sidebar

Related Questions

I have this quick question regarding cost estimation using Function Points. We are doing
Quick question regarding EventHandlers in C#, let's say we have the following code: MyObject.MyEventHandler
I have a quick question regarding debug and release in VS 2008. I have
I am somewhat new to LINQ and have a quick question regarding deleting. Say,
Good afternoon, I have a quick 'top level' question regarding the usage of Facebook
I have a quick question here. I know that the cakePHP find('first') function returns
I have a quick question regarding the creation of absolute URLs within a symfony
I have a quick question regarding memory management that I am not quite sure
I have a quick question regarding a database that I am designing and making
I have a quick question regarding the proper way to access Javascript class member

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.