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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:42:29+00:00 2026-05-15T17:42:29+00:00

I just read this answer by Bill Karwin . Note that the $node is

  • 0

I just read this answer by Bill Karwin.

Note that the $node is pass by reference.

I always thought that variable created there is only ever temporary and exists only until the end of the loop (or maybe it remains set to the last iteration – I have not tested it).

So, what are the advantages of making it pass by reference?

I’m sure there is one, but I can’t figure it out yet.

  • 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-15T17:42:30+00:00Added an answer on May 15, 2026 at 5:42 pm

    It has nothing to do with being faster or more efficient.

    PHP implements copy-on-write so a variable may refer to the same area of memory until you change its value. Then when you change the variable, PHP decides whether or not to create a copy depending on whether you’re accessing it by value or by reference.

    Access by value — changes to a variable creates a copy:

    $a = array("abc");
    
    foreach ($a as $element) {
      $element = "def";
    }
    
    print_r($a);
    
    Array
    (
        [0] => abc
    )
    

    Access by reference — changes to a variable affect the original copy:

    foreach ($a as &$element) {
      $element = "def";
    }
    
    print_r($a);
    
    Array
    (
        [0] => def
    )
    

    Note that all objects in PHP 5 are accessed by reference without using the & operator.
    This is a good reason to use objects!

    Be very careful using references in PHP, because they can have confusing effects.

    Be sure to read this blog: Do not use PHP references by PHP core developer Johannes Schlüter

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

Sidebar

Related Questions

I just read this great answer from BalusC about how to upload files with
I just read on this answer (answer has since been removed) and I'm sure
I've just read this snippet from another answer : When you create a block
I just read this nice answer given on how to compare floating-point values for
I've read every answer available for this question that I could find, including this
I just read this answer Converting upper-case string into title-case using Ruby . There
I just read this question and the accepted answer: What is JavaScript garbage collection?
I just read the accepted answer of this question , which left me with
I just read the top answer at this post: Problem inserting string or NULL
I read this answer, and it just confused me: TicTacToe AI Making Incorrect Decisions

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.