How do you pass a variable by value?

Discussion in 'PHP' started by sparkar17, Mar 23, 2010.

  1. #1
    How do you pass a variable by value? in PHP..
     
    sparkar17, Mar 23, 2010 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    In PHP 4, by default object variables were passed by value, which was quite annoying for OO enthusiasts. In PHP5 however, they're are passed by reference - a great improvement. If you want to pass by value, you may want to look at cloning the current object instance.

    Regular variables are passed by value by default.
     
    Alex Roxon, Mar 23, 2010 IP
  3. angelomaniac

    angelomaniac Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    simply use '=' sign.

    Ex: $my_money = $your_money;
     
    angelomaniac, Mar 23, 2010 IP
  4. blacknet

    blacknet Active Member

    Messages:
    709
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    70
    #4
    yup..

    
    <?php
    Class::method( $value = $myvar );
    
    PHP:
     
    blacknet, Mar 24, 2010 IP