Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Symfony 2.3 branch is *not* fully compatible with PHP 7. #18269

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

Closed
kalzekdor opened this issue Mar 23, 2016 · 18 comments
Closed

Symfony 2.3 branch is *not* fully compatible with PHP 7. #18269

kalzekdor opened this issue Mar 23, 2016 · 18 comments

Comments

@kalzekdor
Copy link

There was a blog post on August 11th claiming that all maintained Symfony branches were 100% compatible with PHP 7. At the time, (and as of right now), 2.3 is a maintained branch.

However, if you view the code under the Debug section, you'll see that there is no support for the new Error type. Function typing should be using \Throwable, but instead are still using \Exception.

Which leads to errors like:

Whoops, looks like something went wrong.
1/1FatalErrorException: Error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Debug\ExceptionHandler::handle() must be an instance of Exception, instance of Error given in ...\vendor\symfony\symfony\src\Symfony\Component\Debug\ExceptionHandler.php:67
Stack trace:

0 [internal function]: Symfony\Component\Debug\ExceptionHandler->handle(Object(Error))

1 {main}

thrown in ...\vendor\symfony\symfony\src\Symfony\Component\Debug\ExceptionHandler.php line 67
in ...\vendor\symfony\symfony\src\Symfony\Component\Debug\ExceptionHandler.php line 67

So... is 2.3 fully compatible with PHP 7 or not?

@linaori
Copy link
Contributor

linaori commented Mar 23, 2016

http://php.net/manual/en/language.errors.php7.php

I think it's 100% compatible, it just shouldn't catch the Errors here and delegate them most likely. All cases will work until you trigger something that would be an Error (Throwable) in php 7 but not in 5.*

@kalzekdor
Copy link
Author

See the stack dump I included. When an Error type is thrown, ExceptionHandler is called and parameterized with the Error. This causes an Exception to be thrown there, which completely obiliterates any contextual information about the original Error (e.g., Stack Trace). Which makes any Errors thrown in PHP 7 nearly impossible to debug.

Exception handling in 2.3 has no provisions for handling the new Error type in PHP 7. Therefore, it would not be 100% compatible with PHP 7, as features are lost when switching to PHP 7.

The weird part is that, as far as I can tell, explicit handling for this exact scenario was implemented in the 2.6 branch, but was never back-ported to 2.3. But 2.3 is still in LTS, so the claim that all supported branches are fully compatible is false. It looks like someone just overlooked merging the changes into 2.3.

@nicolas-grekas
Copy link
Member

@kalzekdor would you mind opening a PR against 2.3?

@kalzekdor
Copy link
Author

@nicolas-grekas Sorry, I'm not too familiar with GitHub, so I'm not sure what you're asking for.

Here is a commit to the 2.6 branch that appears to address the issue, but as far as I can tell it was never applied to the 2.3 branch.

@Simperfit
Copy link
Contributor

@kalzekdor @nicolas-grekas wanted to ask you if wou wanted to correct this issue by forking and working on that issue ;).

@nicolas-grekas
Copy link
Member

Please check #18336

fabpot added a commit that referenced this issue Mar 30, 2016
This PR was merged into the 2.3 branch.

Discussion
----------

[Debug] Fix handling of php7 throwables

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18269
| License       | MIT
| Doc PR        | -

Should not be merged into 2.7 because 2.7 already has the required logic.

Commits
-------

b032096 [Debug] Fix handling of php7 throwables
@fabpot fabpot closed this as completed Mar 30, 2016
@kalzekdor
Copy link
Author

Great! Thanks @nicolas-grekas for the quick turn-around.

@masterjus
Copy link

Hello. It still doesn't work if I register only ExceptionHandler. Like ExceptionHandler::register();

@stof
Copy link
Member

stof commented Apr 19, 2017

@masterjus 2.3 is not maintained anymore though

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 19, 2017

ExceptionHandler needs to be used in conjunction with ErrorHandler, you should not (and cannot on PHP7) use it standalone.

@mlivan
Copy link

mlivan commented Jul 31, 2017

Symfony v2.4.10 also have problem with this bug.

@xabbuh
Copy link
Member

xabbuh commented Jul 31, 2017

Symfony 2.4 is not maintained anymore. You need to update to Symfony 2.7, 2.8, 3.2 or higher.

@mlivan
Copy link

mlivan commented Aug 1, 2017

Yes. Thank you.

@chalasr
Copy link
Member

chalasr commented Aug 1, 2017

As of today 3.2 is not maintained anymore as well.

@sterichards
Copy link

I am having this issue on 2.7 using PHP 7.0.29 (cli)

@curry684
Copy link
Contributor

You are aware 2.7 is going out of active support in 3 weeks? You should urgently upgrade to 2.8 and then 3.4.

https://symfony.com/roadmap?version=2.7#checker

@xabbuh
Copy link
Member

xabbuh commented May 10, 2018

In any case, comments on closed issues are likely to get lost. Please open a new one with some steps on how to reproduce it.

@ameenross
Copy link

If you're still running something on Symfony 2.3 (I won't judge), this may cause you headaches. It seems the code in #18336 is just an incomplete hack.

When an E_NOTICE or anything else passes through the ErrorHandler, it's supposed to call the ExceptionHandler, which in turn serves the user with this:
screenshot from 2018-12-27 15-23-23

The ErrorHandler does that by retrieving the ExceptionHandler first and then checking the below before finally calling the ExceptionHandler:

if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
}

Obviously, since the code in the referenced PR adds a closure as handler, this check evaluates to false. Therefore, no E_NOTICE, E_WARNING etc will ever be translated to an HTML page about the PHP error anymore.

@symfony symfony locked as resolved and limited conversation to collaborators Dec 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests