-1

When I'm using $this inside create_function I'm getting an error

Fatal error: Using $this when not in object context

create_function('$model, $this', 'return $this->di->getStatus($model->getStatus)');

Later on I call it like

$function($model, $this);

I passed $this to the function, but doesn't seems to work. There is a way to get around it?

Thanks

user2035693
  • 193
  • 2
  • 16
  • 1
    I think people assumed (as you havn't shown otherwise) that you're not aware $this` can only be used in a class context. Perhaps show in your question that the function does indeed reside within a class – Martin Apr 03 '16 at 17:59

1 Answers1

0

After hours of debugging and research I found out that my code was being wrapped in a function, so the end result was something like

function($var1, $var2) { return create_function()}

This way a closure was created and $this was no longer in the scope that I wanted.

More about closures here: http://php.net/manual/ro/class.closure.php

user2035693
  • 193
  • 2
  • 16