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

Assign to property by reference ignores functionMap.php #11777

Open
jlherren opened this issue Oct 2, 2024 · 4 comments
Open

Assign to property by reference ignores functionMap.php #11777

jlherren opened this issue Oct 2, 2024 · 4 comments
Labels
Milestone

Comments

@jlherren
Copy link

jlherren commented Oct 2, 2024

Bug report

When a class property is assigned via a function that takes a reference, the type specified in functionMap.php seems to not be taken into account. Or at least it's the case with proc_open(). Although I'm not sure if the types given in functionMap.php are understood to be equivalent to @param-out.

functionMap.php:

'proc_open' => ['resource|false', 'command'=>'string', 'descriptorspec'=>'array', '&w_pipes'=>'resource[]', 'cwd='=>'?string', 'env='=>'?array', 'other_options='=>'array'],

Code snippet that reproduces the problem

https://phpstan.org/r/a76b47ab-8e57-40da-b76e-60fd02c2470e

Expected output

No error.

Did PHPStan help you today? Did it make you happy in any way?

No response

@ondrejmirtes
Copy link
Member

This one is tricky. Basically my fear is that for by-ref parameters, those types in functionMap don't mean anything. I don't want to research that now, but the problem is that for some functions, these types do not enforce the incoming type, and for some functions, these types are different from those assigned by-ref when the function call ends.

That's why "isBuiltin" is mentioned in these places:

My bet is that if you remove those conditions, some tests will fail, and you'll see why.

The path forward for this issue and #11791 is definitely a stub with @param-out :)

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Oct 3, 2024
@piotrekkr
Copy link

I tied this param-out stub and it did not work but maybe I dont get how to work with it. I tried here https://phpstan.org/r/df08d92f-b46e-45c5-88fe-4235a42a0bf6 this

<?php declare(strict_types = 1);

$openSslSignature = '';
/**
 * @param-out string &$openSslSignature
 */
openssl_sign(
    'data',
    $openSslSignature,
    'key contents',
    'SHA256',
);

PHPStan\dumpType($openSslSignature);

with and without&. Still I get same mixed type. How should I use this @param-out? @ondrejmirtes

@ondrejmirtes
Copy link
Member

Register the signature as a stub file and send a PR to phpstan-src: https://phpstan.org/user-guide/stub-files

@piotrekkr
Copy link

@ondrejmirtes Done here phpstan/phpstan-src#3532

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

No branches or pull requests

3 participants