Results 1 to 6 of 6

Thread: What are the References in PHP?

  1. #1
    Join Date
    Aug 2006
    Posts
    162

    What are the References in PHP?

    Hello friends,
    I have done some basic things with the PHP programming language but I am not expert in that. You guys really helped me last time, so I thought to post my doubts here again instead of searching it on web. When I went through the term references, I was blank after that, since I don't know anything about the references.!! Please explain me what are the References in PHP? Any coding related to the same topic would be very grateful.! Expecting some solutions faster.!!
    Technology is a way of organizing the universe so that man doesn't have to experience it.-- Max Frisch 1911 -1991

  2. #2
    Join Date
    Mar 2008
    Posts
    672

    Re: What are the References in PHP?

    You can access the same variable content by different names with the help of References. References in PHP are simpler than the related mechanism found in C and C++. C and C++ use pointers. But you can say that they are not like C pointers, because you cannot perform pointer arithmetic using them. When you try to compare the C++ to the PHP programming language then I would say that using PHP for the references is much better. By using references, you can refer or point to the same data using different variables.

  3. #3
    Join Date
    Aug 2006
    Posts
    235

    Re: What are the References in PHP?

    One thing you will have to keep in mind that in PHP, variable name and variable content are different, so the same content can have different names. You can also do hardlinking in Unix filesystem, by using the references. You can create a reference by assigning a variable with the reference operator just like I have explained below :
    PHP Code:
    $x "data";
    $z =& $x
    A reference in PHP is a variable that "references" the contents of another variable.
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  4. #4
    Join Date
    Jul 2006
    Posts
    286

    Re: What are the References in PHP?

    You can pass a variable by reference to a function so the function can modify the variable. The syntax is as follows :
    PHP Code:
    <?php
    function call(&$var)
    {
        
    $var++;
    }

    $a=5;
    call($a);
    ?>
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What are the References in PHP?

    For passing the reference correctly, functions definition alone are enough. The following things can be passed by reference:
    1. Variables
    2. New statements
    3. References which are returned from functions

    See the following example for explanation :
    PHP Code:
    <?php
    function call(&$var)
    {
        
    $var++;
    }
    function &
    bar()
    {
        
    $a 7;
        return 
    $a;
    }
    call(bar());
    ?>

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: What are the References in PHP?

    The main thing to keep in mind is that references are not pointers. You can perform three basic operations using references. They are described as follows :
    • assigning by reference
    • passing by reference
    • returning by reference.
    PHP references allow you to make two variables refer to the same content. If you assign, pass, or return an undefined variable by reference, it will get created. The following sample of coding explains the same :
    PHP Code:
    <?php
    function call(&$var) { }

    call($a); 

    $b = array();
    call($b['b']);
    var_dump(array_key_exists('b'$b));

    $c = new StdClass;
    call($c->d);
    var_dump(property_exists($c'd')); 
    ?>

Similar Threads

  1. Delete Printer References In the registry
    By Victor Kam in forum Windows XP Support
    Replies: 3
    Last Post: 26-07-2011, 02:13 PM
  2. Want references of programming language to develop site in asp.net
    By Dakshayani in forum Software Development
    Replies: 4
    Last Post: 07-06-2011, 08:24 AM
  3. How to Return and Unset the References in PHP?
    By Silent~Kid in forum Software Development
    Replies: 4
    Last Post: 23-02-2010, 05:24 AM
  4. OpenWrite text references and windows preview
    By Daniel23 in forum Windows Software
    Replies: 5
    Last Post: 31-01-2010, 03:01 AM
  5. How to build cross references in a database
    By Thunder Chicken in forum Software Development
    Replies: 4
    Last Post: 07-11-2009, 07:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,502,445.94612 seconds with 16 queries