Coding style - assigning by reference

Coding style - assigning by reference

by Tomasz Muras -
Number of replies: 1
Picture of Core developers Picture of Plugin developers Picture of Plugins guardians Picture of Translators

I have a (pretty minor) query about coding style. This in in relation to assigning by reference. By looking at the Moodle code, there are 3 different ways that are used to use whitespaces in such a construction:

  1. $mform   =& $this->_form;
  2. $mform = & $this->_form;
  3. $buttonarray[] = &$mform->createElement

I have run it through grep against latest Moodle 2 code - I have included only .php and excluded everything inside the lib directory. The 1st form is the most common: I've found it used 658 times. The other two (2,3) together are much less commonly used: 168 times.

Would everyone here agree that form 1 should be used? It would be nice to get Coding_style page updated with that info as well.

cheers,
Tomasz Muras
Enovation Solutions

Average of ratings: -
In reply to Tomasz Muras

Re: Coding style - assigning by reference

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, in PHP5, you should hardly ever use assign-by-reference. It is never needed with objects, which is what it is being used for in all your 3 examples.