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

  • Home
  • SEARCH
  • 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 586953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:09:38+00:00 2026-05-13T15:09:38+00:00

Im wondering if its good practice to pass-by-reference when you are only reading a

  • 0

Im wondering if its good practice to pass-by-reference when you are only reading a variable, or if it should always be passed as a value.

Example with pass-by-reference:

$a = 'fish and chips';
$b = do_my_hash($a);
echo $b;

function &do_my_hash(&$value){
   return md5($value);
}

Example with pass-by-value:

$a = 'fish and chips';
$b = do_my_hash($a);
echo $b;

function do_my_hash($value){
   return md5($value);
}

Which is better ? E.g if I was to run a loop with 1000 rounds ?

Example of loop:

for($i = 0 ; $i < 1000 ; $i++){
   $a = 'Fish & Chips '.$i;
   echo do_my_hash($a);
}
  • 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-13T15:09:38+00:00Added an answer on May 13, 2026 at 3:09 pm

    If you mean to pass a value (so the function doesn’t modify it), there is no reason to pass it by reference : it will only make your code harder to understand, as people will think “this function could modify what I will pass to it — oh, it doesn’t modify it?“

    In the example you provided, your do_my_hash function doesn’t modify the value you’re passing to it; so, I wouldn’t use a reference.

    And if you’re concerned about performance, you should read this recent blog post: Do not use PHP references:

    Another reason people use reference is
    since they think it makes the code
    faster. But this is wrong. It is even
    worse: References mostly make the code
    slower! Yes, references often make
    the code slower – Sorry, I just had to
    repeat this to make it clear.

    Actually, this article might be an interesting read, even if you’re not primarily concerned about performance 😉

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

Sidebar

Related Questions

I'm wondering if it's a good idea to make verifications in getters and setters
I'm wondering if its possible to add new class data members at run-time in
I was wondering if its possible to inject a thread into a remote app
Yeah, its a bit on this side of pointless, but I was wondering... I've
I was just wondering: PHP is such a good robust thing for make quick
I was wondering if its possible to call an event or method the first
I am wondering if its possible to get the size of the content (
I'm wondering if it's possible to define a foreign key in a models.py file
I was wondering if it's possible to calculate the average of some numbers if
I'm wondering if it's possible to get a handle on running instances of a

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.