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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:06:28+00:00 2026-06-15T16:06:28+00:00

Sorry, Im sure this answer is somewhere on the internet (maybe even stackoverflow) but

  • 0

Sorry, Im sure this answer is somewhere on the internet (maybe even stackoverflow) but I have spent the last hour searching and cant seem to find the answer…

Does PHP’s extract() function add variables to the symbol table using copy-on-write?

I know that PHP function calls all have a copy-on-write by default (unless you specify by reference), just curious about this as I am integrating a templating system so I grab a whole bunch of variables into a $data array, which can be quite large sometimes and am wondering if extracting them before including the template file is the best way to go about this.

thanks!

EDIT:

To clarify:

    $array = array('a' => array(1,2,3), 'b' => array(3,4,5), 'c' => array(6,7,8));
    extract($array);
    //is $a, $b, $c Copy-On-Write at this point? Would be a lot better performance as opposed to allocating 3 new array()'s

    //I would like to avoid having this change the original $array values so using EXTR_REFS is not a good solution for me here if I can avoid it and still keep performance!
    $a = array(3);
  • 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-15T16:06:29+00:00Added an answer on June 15, 2026 at 4:06 pm

    Both versions are possible (extract values and extract by reference) – and it’s quite easy to showcase both:

    function value() {
        $array = array('a' => 1, 'b' => 2);
        extract($array);
        var_dump($a);
        var_dump($b);
        $a = 3;
        $b = 4;
        var_dump($a);
        var_dump($b);
        var_dump($array);
    }
    
    function reference() {
        $array = array('a' => 1, 'b' => 2);
        extract($array, EXTR_REFS);
        var_dump($a);
        var_dump($b);
        $a = 3;
        $b = 4;
        var_dump($a);
        var_dump($b);
        var_dump($array);
    } 
    
    value();
    /* 
    int(1)
    int(2)
    int(3)
    int(4)
    array(2) {
      ["a"]=>
      int(1)    // original array item is unchanged
      ["b"]=>
      int(2)    // original array item is unchanged
    }
    */
    
    reference();
    /*
    int(1)
    int(2)
    int(3)
    int(4)
    array(2) {
      ["a"]=>
      &int(3)    // original array item is changed because it's a reference to the extracted variable
      ["b"]=>
      &int(4)    // original array item is changed because it's a reference to the extracted variable
    }
    

    extract() allows for a second parameter which features EXTR_REFS as an option:

    Extracts variables as references. This effectively means that the
    values of the imported variables are still referencing the values of
    the var_array parameter. You can use this flag on its own or combine
    it with any other flag by OR’ing the extract_type.

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

Sidebar

Related Questions

Sorry I am sure this is easy but I have spent ages trying to
I'm sure there is an answer to this somewhere but I'm clearly using the
I'm not even sure if this is possible but thought I'd ask anyway. Sorry
Sorry, I'm not sure how to search for the answer to this, but I'm
Sorry if the answer to this is obvious, but I want to be sure,
I'm sorry if this question has been asked before, but I'm not even sure
Sorry, this is almost certainly a duplicate, but I've been searching StackOverflow and haven't
Sorry, I'm sure this is simple but I'm tired and can't figure it out.
Sorry but I am not sure how to ask this question but I am
Sorry if this question sounds a little silly, but I am not sure what

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.