Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    278
    Thanks
    63
    Thanked 8 Times in 8 Posts

    func_get_args ... by reference?

    Consider the following code:

    PHP Code:
    function myfunc($a$b$c)
    {
      
    $args =& func_get_args();

      
    $args[0] = 1;

      echo 
    implode(", ", array($a$b$c)).PHP_EOL;
    }

    myfunc(223); 
    This outputs 2, 2, 3. Is there a built-function, akin to func_get_args, which returns an array of references to the function arguments, rather than copies? I can't find anything in the manual, but perhaps I'm looking in the wrong place!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    No, there is no way to pass by reference values created by func_get_args. You will need to specify them inside of the parameter list instead.

    In PHP 5.x+ you can use objects which will use a object pointer to work with instead.

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Posts
    278
    Thanks
    63
    Thanked 8 Times in 8 Posts
    How does the object point work? I have PHP 5.3.3.

    EDIT: Oh, yes I understand. Ignore my question!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •