Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet force-pushed the fix/12364 branch 2 times, most recently from 64793f6 to 9f4771a Compare December 5, 2025 16:16

use function PHPStan\Testing\assertType;

/** @return array{x: string, y?: string} */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add z?: string here and test it without assigning first.

I'd say that if $scope->canAnyVariableExist() is true and variable certainty is maybe, $z has to be mixed after extract.

The script can be included from somewhere where $z is already defined and is of a different type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +13 to +18
assertType('null', $x);
assertType('null', $y);
extract(foo());
assertType('string', $x);
assertType('string|null', $y); // <-- should be: null|string
assertType('mixed', $z);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would also make sense to assertVariableCertainty on the 3 vars

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

assertType('string|null', $y); // <-- should be: null|string
assertType('mixed', $z);
assertVariableCertainty(TrinaryLogic::createYes(), $x);
assertVariableCertainty(TrinaryLogic::createYes(), $y); // <-- should be: null|string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertVariableCertainty(TrinaryLogic::createYes(), $y); // <-- should be: null|string
assertVariableCertainty(TrinaryLogic::createYes(), $y);

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

Successfully merging this pull request may close these issues.

extract() applied to an array with optional keys should not mark the corresponding extracted variables as potentially undefined

3 participants