CRM-8597 PHP strict warning: Only variables should be assigned by reference.

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.0.4
    • Fix Version/s: 4.1.0
    • Component/s: None
    • Labels:
      None

      Description

      CiviCRM quite frequently uses the following paradigm:

      $foo =& ClassName::functionName();

      Unless CiviCRM is striving for compatibility with PHP 4, the ampersand should be dropped:

      $foo = ClassName::functionName();

        Attachments

          Activity

          [CRM-8597] PHP strict warning: Only variables should be assigned by reference.
          Bob Vincent added a comment -

          The attached civicrm-only_variables_should_be_assigned_by_reference-CRM-8597.patch is the result of running the following script over a fresh svn trunk checkout:

          find . -path ".svn" -prune -o -type f -exec perl -pi -e 's,= & *([a-zA-Z0-9_]::[a-zA-z0-9_](.?),= \1,' '{}'

          Bob Vincent added a comment -

          Further testing (and reading docs) shows that the ampersand is required in some cases.

          The warning is issued when the function in question returns the result of an expression rather than a declared variable.

          Where the function is returning an object, the ampersand is unnecessary and should be dropped.

          Where the function is returning a scalar or an array, the ampersand should be kept, but the function should be careful to only return a variable, never an expression.

          Rohan S. Chavan added a comment -

          Fixed in r35731

            People

            • Assignee:
              Rohan S. Chavan
              Reporter:
              Bob Vincent

              Dates

              • Created:
                Updated:
                Resolved: