Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php fatal error with php 8.0.0 #492

Open
Ponce opened this issue Nov 28, 2020 · 6 comments
Open

php fatal error with php 8.0.0 #492

Ponce opened this issue Nov 28, 2020 · 6 comments

Comments

@Ponce
Copy link

Ponce commented Nov 28, 2020

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.

@ph1lt0r
Copy link

ph1lt0r commented Feb 6, 2021

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

@marioscube
Copy link

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?

@kounch
Copy link

kounch commented Feb 15, 2021

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.

@timtoo
Copy link

timtoo commented Mar 3, 2021

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.

@marioscube
Copy link

marioscube commented Mar 3, 2021

@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).

@mikespub
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants