Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4

Thread: By Reference

  1. #1
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Is there a non-depreciated way of passing variables to functions by reference instead of by value?
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  2.  

  3. #2
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Declaring the function with & works for me.

    Following example works without the warning:
    PHP Code:
    <?php 
    function test(&$x)
    {
        
    $x $x+2;
        echo 
    "In The Function: $x<br>"
    }
    $a 5;
    echo 
    "Before Function Call: $a<br>"
    test($a);
    echo 
    "After Functions Call: $a<br>"
    ?>

    //output
    Before Function Call: 5
    In The Function: 7
    After Functions Call: 7
    Hope that helps
    There and Back Again :Ogre:

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Thanks. For some reason I thought that was deprecated but I guess not.

    Second question: are there pointers in PHP? If there are then I'm in heaven for this project I'm working on
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    It is deprecated to pass it using function(&$a), however, to avoid the warning you need to place & in the function declaration and call it as you normally would.

    There are no pointers in PHP, but references ( name change, big deal ).

    http://www.php.net/manual/en/language.references.php
    There and Back Again :Ogre:


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:24 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com