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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:15:17+00:00 2026-05-27T18:15:17+00:00

I am following class based coding for project development.I have recently seen that some

  • 0

I am following class based coding for project development.I have recently seen that some times we put “&” ahead of function name..

for an example..

rather than defining

function test()

it is defined like

function &test()

is there any special meaning of “&”?

  • 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-27T18:15:18+00:00Added an answer on May 27, 2026 at 6:15 pm

    As @philip mentions, it is to return a reference:

    From the above link:

    Note: Unlike parameter passing, here you have to use & in both places – to indicate that you want to return by reference, not a copy, and to indicate that reference binding, rather than usual assignment, should be done for $myValue.


    PHP stores every variable in a ZVAL container.

    From the above link:

    A zval container contains, besides the variable’s type and value, two additional bits of information.The first is called “is_ref” and is a boolean value indicating whether or not the variable is part of a “reference set”. With this bit, PHP’s engine knows how to differentiate between normal variables and references. Since PHP allows user-land references, as created by the & operator, a zval container also has an internal reference counting mechanism to optimize memory usage. This second piece of additional information, called “refcount”, contains how many variable names (also called symbols) point to this one zval container.


    Observe the values of variable in the output:
    Consider the following without & at the assignment of return value:

    $b=0;
    function &func ($name) {
      global $b;
      $b = 10;
      return $b;
      }
    $a = func("myname");// no & at assignment
    ++$a ;
    echo '<br/>$a= '.$a.' $b= ' .$b."<br/>";
    xdebug_debug_zval('a'); echo "<br/>";
    

    The output for the above code:

    $a= 11 $b= 10
    a: (refcount=1, is_ref=0)=11 
    

    Although the function returns by reference, the reference is for the returned value’s zval container. Now, when we are trying to assign the returned value, (say without a & at the assignment) only the “refcount” will increase. Where as the “is_ref” will not be altered. When the ‘variable in which the returned value is stored’, is tried to alter, a C.O.W (copy on write) takes place and a new zval container is created rendering the return by reference useless. Hence you will need to add the & at the assignment of the return value as well.

    Consider the following with & at the assignment of return value:

    $b=0;
    function &func ($name) {
      global $b;
      $b = 10;
      return $b;
      }
    $a =& func("myname");// & at assignment
    ++$a ;
    echo '<br/>$a= '.$a.' $b= ' .$b."<br/>";
    xdebug_debug_zval('a'); echo "<br/>";
    

    The output:

    $a= 11 $b= 11
    a: (refcount=2, is_ref=1)=11 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class definition. Contact.h #import <CoreData/CoreData.h> @interface Contact : NSManagedObject {
I had a frustrating problem recently that boiled down to a very simple coding
My style of coding includes the following idiom: class Derived : public Base {
Rails 3.0.3 and Ruby 1.9.2 I have the following class class item < ActiveRecord::Base
I'm trying the following based on scalatra-sbt.g8: class FooWeb extends ScalatraServlet with ScalateSupport {
I have the following: class Car < ActiveRecord::Base has_one :driver end class Driver <
I have the following setup: class.staff.php This defines many variables, the one I'm working
I'm trying to improve my coding style. Consider the following scenario: Suppose that I
I try to read an XML file that contains the following element: <ho:CODED-TYPE ho:BASE-DATA-TYPE=A_UINT16
I have a SharePoint web part that I wrote in C# which is used

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.