-1

I just updated my server to the latest version of php 7.2 and now I have some depreciation warnings. What should I do?

This function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged.

Here is my code:

if(!array_key_exists('callable', $this->translation_plural)) {
    $this->translation_plural['callable'] = create_function('$n', $this->translation_plural['function']);
}
rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38

1 Answers1

0

The documentation recommends using anonymous functions. Given that $this->translation_plural['function'] looks like it is a string, you should consider a rewrite.

If you want to get rid of the warning, you can use the following:

$this->translation_plural['callable'] = function($n) { return eval($this->translation_plural['function']); };

This doesn't help your code at all, you are still using eval() which is bad practise. The documentation warns against using it.

The only difference is, create_function() used it internally, now it is very explicit.

miken32
  • 42,008
  • 16
  • 111
  • 154
rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38