Skip to content

implement LtrimFunctionReturnTypeExtension to support class-string#1597

Merged
ondrejmirtes merged 3 commits intophpstan:1.8.xfrom
staabm:ltrim
Aug 6, 2022
Merged

implement LtrimFunctionReturnTypeExtension to support class-string#1597
ondrejmirtes merged 3 commits intophpstan:1.8.xfrom
staabm:ltrim

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Aug 6, 2022

@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace Bug7483;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried supporting things like

function bar() {
	$absolute = '\A';
	$relative = 'A';

	assertType('class-string', ltrim($absolute, '\\'));
	assertType('class-string', ltrim($relative, '\\'));
}

but from the extension point of view these strings seem not to be class-strings...?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ConstantStringType::isClassString() is just a hint whether the string was created from ::class, so that we don't trigger the autoloading for irrelevant strings, which upsets some custom autoloaders.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So you don't need to do anything about it.

@staabm staabm marked this pull request as ready for review August 6, 2022 09:15
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace Bug7483;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ConstantStringType::isClassString() is just a hint whether the string was created from ::class, so that we don't trigger the autoloading for irrelevant strings, which upsets some custom autoloaders.

@ondrejmirtes ondrejmirtes merged commit e91de77 into phpstan:1.8.x Aug 6, 2022
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you.

@staabm staabm deleted the ltrim branch June 21, 2023 15:09
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.

ltrim(class-string, '\\') is always a class-string

2 participants