Skip to content

More precise dirname() return type#5708

Merged
staabm merged 1 commit into
phpstan:2.1.xfrom
staabm:456
May 19, 2026
Merged

More precise dirname() return type#5708
staabm merged 1 commit into
phpstan:2.1.xfrom
staabm:456

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented May 19, 2026

given a non-empty-string-path, dirname() will return a non-empty-string

see e.g. https://3v4l.org/YK9T1#veol


we applied the same logic already for pathinfo:

$builder->setOffsetValueType(new ConstantStringType('dirname'), new StringType(), !$pathType->isNonEmptyString()->yes());


use case: prevents a

Configuration defined type for constant APP_ROOT (non-empty-string) does not accept value string.

error in define('APP_ROOT', dirname(__DIR__, 2)); when using dynamicConstantNames

@staabm staabm requested a review from VincentLanglet May 19, 2026 12:57
@staabm staabm merged commit 8678cca into phpstan:2.1.x May 19, 2026
656 of 658 checks passed
@staabm staabm deleted the 456 branch May 19, 2026 13:18
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.

2 participants