skip to Main Content

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


  1. If you add variable $di (factory) to your application

    you need to write this :

    $this->di->session->get('auth');
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search