Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 8, 2025

{
$mask = substr($mask, 0, strlen($data));
$data ^= $mask;
return(base64_encode($data));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was reporting an error on level 5 on php 7.4 https://phpstan.org/r/12e63cdd-d516-4db2-a314-51da4f5c3101

{
assertType('int', $a & $b);
assertNativeType('int', $a & $b);
assertNativeType('*ERROR*', $a & $b);
Copy link
Contributor Author

@VincentLanglet VincentLanglet Dec 5, 2025

Choose a reason for hiding this comment

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

This is equivalent to mixed & mixed which is now reported as an error. (we can't be sure it's an int, it could be string & string for instance or worst, int & string)

Copy link
Contributor

Choose a reason for hiding this comment

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

if we can't know what it is, why is it an ERROR then? shouldn't it be mixed instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current mixed behavior is weird. A good example of the issue is

int ^ mixed = ? // currently int ; so no error is reported InvalidBinaryOperationRule
string ^ mixed = ? // currently Error ; an error is reported by InvalidBinaryOperationRule
mixed ^ mixed = ? // currently int ; so no error is reported by InvalidBinaryOperationRule

I'm not sure what should be done. Either error for all or something like

int ^ mixed = int
string ^ mixed = string
mixed ^ mixed = (int|string)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried another solution, tell me your opinion about it @staabm :)

@VincentLanglet VincentLanglet force-pushed the bug8094 branch 2 times, most recently from 5866d4a to 6e91d05 Compare December 5, 2025 11:40
@ondrejmirtes ondrejmirtes merged commit ab48233 into phpstan:2.1.x Dec 6, 2025
636 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

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.

Xor operation on strings on PHP 7.x is viewed as conversion to int

3 participants