1

My code snippet:

public static function saveEntryView($content, $conf, $m_name, $m_firstname, $m_street, $m_zipcity, $m_phone, $m_email, $m_rooms, $m_etage, $m_wohnberechtigungsschein, $m_member, $m_mieter, $m_termin, $m_size, $m_msg ) 
{


    self::$conf['template'] = '/home/www/p422082/html/typo3/fileadmin/wgkw/templates/wgkwcontactform.html';

Before I had:

$this->$conf['template'] = '/home/www/p422082/html/typo3/fileadmin/wgkw/templates/wgkwcontactform.html';

Which basically says that I'm calling non-static object in a static function and gave me this error(totally fair):

Using $this when not in object context 

And led me to following topic PHP Fatal error: Using $this when not in object context and there I've found that it can be changed to:

self::$conf['template'] = '/home/www/p422082/html/typo3/fileadmin/wgkw/templates/wgkwcontactform.html';

But it gives me Access to undeclared static property: $conf error.

Which led me to this topic: Access to undeclared static property $this

which is basically going back to the beggining where the problem has started and this has left me quite confused. Appreciate any help/tips.

Ženia Bogdasic
  • 117
  • 1
  • 17
  • 1
    When defining ``$conf`` instance variable you need to make it static, i.e. ``private static $conf``. – alistaircol Aug 21 '17 at 13:41
  • This would give me syntax error, unexpected 'private' (T_PRIVATE) – Ženia Bogdasic Aug 21 '17 at 13:52
  • Could you post how you define your class and how you declare ``$conf``. – alistaircol Aug 21 '17 at 14:03
  • Try setting your function without static in it like this: `public function saveEntryView(args here)`, and revert to your first object property call `$this->$conf['template']` – Denis Solakovic Aug 21 '17 at 14:04
  • @alistaircol It's like this: public static function saveEntryView($content, $conf, ...) – Ženia Bogdasic Aug 21 '17 at 14:11
  • @DenisSolakovic It starts complaining at the next line PHP Warning: file_get_contents(): Filename cannot be empty and I guess I have to dig into that one now. – Ženia Bogdasic Aug 21 '17 at 14:11
  • You can edit your question and add the PHP Warning: file_get_contents(): thing in. But try to sort it out first XD – Denis Solakovic Aug 21 '17 at 14:13
  • Please [edit] your question to clarify what you are trying to achieve. Don’t you simply want to define a [static property](https://www.php.net/manual/en/language.oop5.static.php#language.oop5.static.properties)? – Melebius Aug 23 '22 at 05:25

0 Answers0