Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 8, 2025

assertType('*ERROR*', $string & $mixed);
assertType('*ERROR*', $stringOrInt & $stringOrInt);
assertType('*ERROR*', $stringOrInt & $mixed);
assertType('*ERROR*', $mixed & $mixed);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Mixed & mixed - should not be a error, right?

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 proposed a solution to get some feedback.

Things like
String ^ int|string
Int ^ int|string

Are already considered as an error because int ^ string is an error.

We have
Int ^ mixed considered to be int (even if it could ends up with int ^ string ?)
String ^ mixed considered to be an error (because it could ends up with string ^ int ?)

So I dunno what we want for mixed ^ mixed but it should not be considered as int. I see three solution:

  • error
  • int|string
  • benevolentUnion int|string

I also dunno if we should change string ^ mixed.

I think we will need a decision from @ondrejmirtes unless you have a good suggestion @staabm ? ^^'

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we should not treat something as an error, if it might be valid. mixed could be a int but just not typed.

therefore I think mixed ^ mixed should be a union of all possible results ^ can have.

but lets wait for ondrej

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO we should not treat something as an error, if it might be valid. mixed could be a int but just not typed.

therefore I think mixed ^ mixed should be a union of all possible results ^ can have.

Currently the InvalidBinaryOperationRule is using the strategy of checking if the result is an error in order to report it. So if you change int ^ int|string from Error to int this won't be reported anymore by the rule.

As an example, this is the current behavior with int + int|array (an error and not an int)
https://phpstan.org/r/7f8dda05-7a6e-49d0-959e-e4bf4f038586

Following the existing strategy, it make sens to have int ^ int|string and string ^ int|string an error.
I just dunno what is expected for mixed...
Currently the fact mixed ^ mixed still allow it to be reported by the rule because on higher level, mixed is transform into strictMixed and strictMixed ^ strictMixed is an Error.

So the question might be

int ^ mixed = ? // currently int ; should be Error or string string ^ mixed = ? // currently Error ; should be Error or string mixed ^ mixed = ? // currently int ; should be Error or int|string 
{
$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

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