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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:01:18+00:00 2026-06-06T19:01:18+00:00

Example: function create_pets(&$cats, &$dogs){ $dogs = get_dogs(); $cats = get_cats(); } so I would

  • 0

Example:

function create_pets(&$cats, &$dogs){
 $dogs = get_dogs();
 $cats = get_cats();
}

so I would call it like:

function foo(){
  create_pets($cats, $dogs);

  // here use $cats and $dogs variables normally
}

I know that I could just assign a new varible the return value of one of those getter functions, but this is just an example. In my situation there’s more than just a getter…

  • 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-06T19:01:21+00:00Added an answer on June 6, 2026 at 7:01 pm

    The answer as everyone says is “it depends”. In your specific example, a “create” function, the code is less obvious to work with and maintain, and thus it’s probably a good idea to avoid this pattern.

    But here’s the good news, there’s a way of doing what you are trying to do that keeps things simple and compact while using no references:

    function create_pets(){
        return array(get_dogs(), get_cats());
    }
    
    
    function foo(){
        list($dogs, $cats) = create_pets();
        //here use $cats and $dogs variables normally
    }
    

    As you can see you can simply return an array and use the list language construct to get the individual variables in a single line. It’s also easier to tell what’s going on here, create_pets() is obviously returning new $cats and $dogs; the previous method using references didn’t make this clear unless one inspected create_pets() directly.

    You will not find a performance difference of using either method though, both will just work. But you’ll find that writing code that is easy to follow and work on eventually goes a long way.

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

Sidebar

Related Questions

I want to create a simple menu function which can call it example get_menu()
I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
for example, say I use a factory to create a group of objects: function
I would like to create a single function to automate htmlwireups. Some portions of
I want to be able to create modal dialogs, with, for example close: function()
I created this example The remove function doesn't work, and I can't figure out
For example: (function() { var proxied = window.eval; window.eval = function() { return proxied.apply(this,
For example : function masterMethod(this, action){ // (action); <-- But action requires $(this) to
I have an example function below that reads in a date as a string
i am wondering abt the example W3C Offline Web Apps the example function renderNotes()

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.