cops icon indicating copy to clipboard operation
cops copied to clipboard

php fatal error with php 8.0.0

Open Ponce opened this issue 5 years ago • 6 comments

cops' index.php with php 8.0.0 produces a blank page and I got this in my php errors log:

28-Nov-2020 15:43:13 Europe/Paris] PHP Fatal error:  Uncaught Error: Call to undefined function create_function() in /var/www/htdocs/cops/vendor/seblucas/dot-php/doT.php:94
Stack trace:
#0 /var/www/htdocs/cops/index.php(53): doT->template()
#1 {main}
  thrown in /var/www/htdocs/cops/vendor/seblucas/dot-php/doT.php on line 94

seems like create_function has been deprecated with php-7.2 and removed in 8.0.0 together with much other deprecated stuff.

Ponce avatar Nov 28 '20 15:11 Ponce

Same issues. Any way to fix this? or is this a major issue?

ph1lt0r avatar Feb 06 '21 20:02 ph1lt0r

The (1st?) error is a deprecated function in php 8 "create_function" on line 94 of doT.php.

The fix should be something like this: Old: return @create_function ('$it', $func);

New:

return @function ($it) use ($func) {
        eval($func);
        };

However on php 7 (don't have 8 yet) this does not work (it should?) and there is no error (in my setup), so I do not know what goes wrong (not much of a programmer myself).

Anyone with php knowledge who can fix this for us?

marioscube avatar Feb 15 '21 18:02 marioscube

Tried

The (1st?) error is a deprecated function in php 8 "create_function" on line 94 of doT.php.

The fix should be something like this: Old: return @create_function ('$it', $func);

New:

return @function ($it) use ($func) {
        eval($func);
        };

However on php 7 (don't have 8 yet) this does not work (it should?) and there is no error (in my setup), so I do not know what goes wrong (not much of a programmer myself).

Tried on php 8. There's also no error, and no page.

kounch avatar Feb 15 '21 18:02 kounch

I fiddled with it (I don't actually know php), and the following replacement code worked for me with PHP 8:

return function ($it) use ($func) {
        return eval($func);
        };

Apparently the security implications of using eval() was the reason create_function() was deprecated (it used it internally, and it's a bit astonishing it took php this long to get rid of such a thing), so seemingly re-creating create_function() using eval() above doesn't feel great! But here we are. Good to have my COPS alive again.

timtoo avatar Mar 03 '21 16:03 timtoo

@timtoo

What a difference a RETURN makes! And works (for me so far) without the @! Maybe needs more testing......

Must have overlooked that permutation (no clue about php either). ;-)

Thank you!

It also seems to work with php 7.4 for me (don't have 8 installed).

marioscube avatar Mar 03 '21 18:03 marioscube

Included in #522 and release 1.2.0 at https://github.com/mikespub-org/seblucas-cops

mikespub avatar Jul 14 '23 20:07 mikespub