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

Cannot see deprecated warnings #761

Open
solodm opened this issue May 5, 2023 · 2 comments
Open

Cannot see deprecated warnings #761

solodm opened this issue May 5, 2023 · 2 comments

Comments

@solodm
Copy link

solodm commented May 5, 2023

Checked versions are Psy Shell v0.11.12 (PHP 7.4.33) and Psy Shell v0.11.16 (PHP 7.4.33).

When we run code

error_reporting(E_ALL);$a = 1?5:1?6:7;

It returns 6 as all is ok.

But if we use the php interactive shell (and there are some several ways to have been hurted by this message), we get warning

root@3cb2be255823:/var/www/html# php -a
Interactive mode enabled

php > error_reporting(E_ALL);
php > $a = 1?5:1?6:7;

Deprecated: Unparenthesized a ? b : c ? d : e is deprecated. Use either (a ? b : c) ? d : e or a ? b : (c ? d : e) in php shell code on line 1

So, why Psy keeps silence about it?

@bobthecow
Copy link
Owner

Because you're not running code without parenthesis 🙁

If you run PsySH with debugging output (psysh -vvv) it'll write the actual code evaluated along with the output. In this case, we can see that there are, in fact, parenthesis:

Screenshot 2023-05-05 at 8 40 20 AM

The reason this is happening is because PsySH can't actually execute raw user input. It requires pre-processing to create the illusion of a REPL in userland 😛

For example, take namespaces. php -a doesn't do what you'd expect with namespaces, because each new input is an eval(), so you get this:

Screenshot 2023-05-05 at 8 47 24 AM

PsySH, on the other hand, acts just like you'd expect:

Screenshot 2023-05-05 at 8 48 06 AM

… but that's because, behind the scenes, it's doing something you very much don't expect:

Screenshot 2023-05-05 at 8 48 32 AM

strict_types has similar issues in php -a:

Screenshot 2023-05-05 at 9 05 08 AM

Screenshot 2023-05-05 at 9 06 10 AM

PsySH does all this with a feature called "code cleaners". They parse input and run a bunch of transformers on it—doing everything from this namespace emulation, to input validation, to converting fatal errors to runtime errors, to return value wrangling, to making exit do what you expect—and the code they output is what is actually eval'd.

This is the man behind the curtain. It is a big piece of the magic that makes PsySH work, but doesn't come without its downsides.

In this case, the trip through tokenizing and parsing loses the fact that, originally, there weren't any parenthesis there. Because the output is just an AST writing to code, which of course emits valid code. It might be possible to detect and warn on the issue during the parsing phase, and I'll look into that, but that would be using more tricks to emulate this behavior, which as we've seen can have some downsides ¯\_(ツ)_/¯

@solodm
Copy link
Author

solodm commented May 11, 2023

Thanks a lot of good explanations and examples. I love psysh. However I decided to create this issue not for make psysh better only, but being in hope that I can find some information in this discussion. I try to understand why we get such warning in the unit-test in our gitlab pipeline but we don't see it at our all other kinds of running, including the same code and the same auto-test.

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

2 participants