Call=time pass reference QUESTION?

Discussion in 'PHP' started by LongBeachIsland, Feb 1, 2011.

  1. #1
    Sorry if this seems like a stupid question but I know absolutely nothing about Php. I have come across the "Call-time pass-by-reference has been deprecated" error many times I find it usually around code that looks like this
    $size = getimagesize ($photo,&$info);
    if(isset ($info["APP13"]))
    {
    PHP:
    I stop getting the error if I remove the & I don't know if this effects the operations of the script however, it just stops the error. I read somewhere that the "Call-time pass-by-reference has been deprecated" basically means that the code is or will be obsolete or is no longer or will no longer be supported. I also heard that adding the line allow_call_time_pass_reference to my php.ini file will fix this error. So my question is should I delete all the & directly before the $ or add the code to the .ini file. Obviously I would be better off using the corrector newer method of the code but as I said I don't know anything about PHP. Suggestions or help would be much appreciated.
     
    LongBeachIsland, Feb 1, 2011 IP
  2. GreenWithEnvy

    GreenWithEnvy Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #2
    http://www.php.net/manual/en/language.references.pass.php
    By reference can only be used when defining a function. The & indicates passing by reference.

    http://us3.php.net/manual/en/function.getimagesize.php

    Referring to there you see that array &$imageinfo is already passed by reference.

    Long story short, remove the & sign it is unnecessary.
     
    GreenWithEnvy, Feb 1, 2011 IP
  3. LongBeachIsland

    LongBeachIsland Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok Thanks for your help I just wanted to make sure. I will do a search on the files to make sure all the instances of &$ are changed to simply $
     
    LongBeachIsland, Feb 1, 2011 IP
  4. GreenWithEnvy

    GreenWithEnvy Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Make sure that you're not replacing any delcared functions though...

    For example, if the code is
    $variable = 6;
    function myFunction ($variablebyvalue, &$variablebyref) //DO NOT REMOVE THE & HERE
    {
    $variablebyref = 0;
    }
    myFunction(1, &$variable); //REMOVE THE & HERE
    echo $variable;
    PHP:
    If you remove the & sign where the function is declared, the script will output 6 instead of 0. The error is being triggered when you place the & where the function is called.

    Good luck!
     
    Last edited: Feb 2, 2011
    GreenWithEnvy, Feb 2, 2011 IP