When developing a Joomla extension, and most likely a standalone extension you receive the following error or similiar:
Strict Standards: Only variables should be assigned by reference in /plugins/editors-xtd/executecode/script.php on line 22
Solution
The error is most likely down to a line similiar to this
$app =& JFactory::getApplication('administrator');
Notice the =&, in PHP5+ you should not longer use this. The line should look like this without the &
$app = JFactory::getApplication('administrator');
Explanation
Remove the & because as off PHP5 it is no longer required and is still only present in PHP5 for legacy code and will be removed in further iterations of PHP.
As of PHP 5, the new operator returns a reference automatically, so assigning the result of new by reference results in an E_DEPRECATED message in PHP 5.3 and later, and an E_STRICT message in earlier versions.
My understanding of this is that PHP5 automatically creates a reference to the objects value and does not copy the value, this makes =& redundant because you no longer need to manually specify this feature. With a reference if you alter the value in either the variable or the object value then the other is changed aswell, hence the term reference.
If you look in the Joomla index.php files you will see there is no =&
// Instantiate the application. $app = JFactory::getApplication('site'); or in the administrator // Instantiate the application. $app = JFactory::getApplication('administrator');
Other Solutions
These are some other solutions I have come across that people use
- Append @ to the beginning of the statement, this causes PHP to supress errors for this statement
@$app =& JFactory::getApplication('administrator');
- Supress errors via the php.ini file
These should be avoided as hiding errors does not mean they have been fixed.
Links
- Dealing with E_STRICT in Joomla - Stack Overflow
- Joomla ‘Strict Standards: Only variables should be assigned by reference’ Error
- Strict Standards: Only variables should be assigned by reference PHP 5.4 - Stack Overflow
- Joomla Man Forum :: Topic: Error "Strict standards: Only variables should be assigned by reference in..." (1/1)
- How to fix the Strict Standards: Non-static method Joomla error