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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post

    function &translateModel(&$model) is a reference function?

    i understand &$model means passing by reference? like in java or C++


    but i dont understand what & for &translateModel


    anyone knows what this is?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Returned by reference. This is an interesting one, essentially you bind a variable to the results of a function. As it changes, the results originally placed change as well. The only time I've needed to use this was when I used a counter & time elapse within post-parsed templating (since the templates were not developed until the last step). This was necessary otherwise the resulting time and counts were limited to the time the function had been called instead of the time and counts upon completion (including the queries for the template data itself).

    That make sense? This is a harder one to explain, but it would be quite reflective of returning a void * from you're function in C.
    Here is some information about its usage: http://php.ca/manual/en/language.references.return.php
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post
    hmmm thanks i have never used this trick in php.... thanks

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Yep, np. Not really a trick though; it has very limited usefullness (like variable variables hah). So far, I've used this approach only once, and haven't really found a situation it was necessary in again (and as specified, unlike C with returning a pointer, PHP will have no benefit in performance by this usage since it uses a copy-on-write approach to its variables anyway).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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