Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 19, 2025

Naming to debate ? __stringwithoutstringable ? __strictstring ?

intval($stringable) is never allowed, even without strict_types.

The current check in FunctionCallParameterCheck is

$this->ruleLevelHelper->accepts($parameterType, $argumentValueType, $scope->isDeclareStrictTypes());

either we're doing something like

$this->ruleLevelHelper->accepts(
      $parameterType,
      $argumentValueType,
      $scope->isDeclareStrictTypes() || in_array($functionName, ['floatval', 'intval', 'doubleval'], true)
);

either we have to introduce the opposite of StringAlwaysAcceptingObjectWithToStringType like I did.

Closes phpstan/phpstan#6560
Closes #1005

@VincentLanglet VincentLanglet force-pushed the fix/6560-string branch 2 times, most recently from 20054a8 to ea50ab0 Compare October 19, 2025 19:10
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Look at StringAlwaysAcceptingObjectWithToStringType. Every new Type implementation also has to override isSuperTypeOf to give correct answers.

You can test that in TypeCombinatorTest::testUnion and testIntersect.

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.

Handle different ways to cast the same

2 participants