I need reanimate an old site, that was made by another programmer a long time ago. The site is built on Phalcon and I don’t know which versions of PHP are supported.
I’m seeing many errors like:
Using $this when not in object context
It is triggered because in Models many functions calls core functions of Phalcon like $this->session->get('auth')
, but it looks like a new version of PHP doesn’t allow it.
How can I fix it without a total rewrite of all models?
Is there any other way to call Phalcon’s $this
in Model?
Or is it not possible?
2
Answers
If you add variable
$di
(factory) to your applicationyou need to write this :
You are calling a static method, therefore an object has not been created and there IS NO $this.
Static methods are BAD, try and avoid! They’re essentially standalone functions hiding inside a class. They’re also very annoying to test.