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

Forbid empty() #6388

Closed
ro0NL opened this issue Sep 2, 2021 · 4 comments · Fixed by #6391
Closed

Forbid empty() #6388

ro0NL opened this issue Sep 2, 2021 · 4 comments · Fixed by #6391

Comments

@ro0NL
Copy link
Contributor

ro0NL commented Sep 2, 2021

I tried

    <forbiddenFunctions>
        <function name="dd"/>
        <function name="dump"/>
        <function name="empty"/>
    </forbiddenFunctions>

without success. I know empty() is a language construct, but to me it's just a function :}

@psalm-github-bot
Copy link

Hey @ro0NL, can you reproduce the issue on https://psalm.dev ?

@ro0NL
Copy link
Contributor Author

ro0NL commented Sep 2, 2021

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/64501b6f92
<?php
var_dump('booooo');
empty('yayyyy');
Psalm output (using commit eb973ab):

ERROR: ForbiddenCode - 2:1 - Unsafe var_dump

@weirdan
Copy link
Collaborator

weirdan commented Sep 2, 2021

but to me it's just a function

It's not to php parser though. Should be fairly easy to add in src/Psalm/Internal/Analyzer/Statements/Expression/EmptyAnalyzer.php, similar to how it's done for print():

if (isset($codebase->config->forbidden_functions['print'])) {
if (IssueBuffer::accepts(
new ForbiddenCode(
'You have forbidden the use of print',
new CodeLocation($statements_analyzer->getSource(), $stmt)
),
$statements_analyzer->getSuppressedIssues()
)) {
// continue
}
}

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

Successfully merging a pull request may close this issue.

2 participants