In Joomla 3:
I'm writing a class to represent a semi-complex data structure. In that class, some methods need to access the app, dbo, document and user objects from JFactory.
Here's a snippet of the code:
class Survey {
use Joomla\CMS\Factory;
private $app = JFactory::getApplication();
private $doc = JFactory::getDocument();
private $db = JFactory::getDbo();
I'm getting an error on the line private $app = JFactory::getApplication();
, the error is:
Fatal error: Constant expression contains invalid operations in /joomla path/media/tmpl/classSurvey.php on line 46
I've also tried to set it up inside the constructor, but I get the same error message:
function __construct($surveyID = -1) {
$this->app = JFactory::getApplication();
$this->doc = JFactory::getDocument();
$this->db = JFactory::getDbo();
Do I need to get these objects outside the class and pass them via the constructor?
Forgive me if this is the wrong place to ask this, but it seemed to be the only Stack Exchange site related to Joomla I could find.
Thanks!