Skip to content

More precise microtime() return type#4347

Merged
ondrejmirtes merged 1 commit intophpstan:2.1.xfrom
takaram:improve_microtime
Feb 5, 2026
Merged

More precise microtime() return type#4347
ondrejmirtes merged 1 commit intophpstan:2.1.xfrom
takaram:improve_microtime

Conversation

@takaram
Copy link
Copy Markdown
Contributor

@takaram takaram commented Sep 18, 2025

Return value of microtime(false) is never falsy.


public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
{
$stringType = new IntersectionType([new StringType(), new AccessoryNonFalsyStringType()]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure it will be helpful, but I think we could in addition make it a AccessoryLowercaseStringType

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why? It is neither LC or UC, thus it should be accepted also by uppercase-string type.

Copy link
Copy Markdown
Contributor

@VincentLanglet VincentLanglet Feb 7, 2026

Choose a reason for hiding this comment

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

Why? It is neither LC or UC, thus it should be accepted also by uppercase-string type.

You can be both LC and UC.
For instance 42 is both.

So we should add both accessory AccessoryLowercaseStringType and AccessoryUppercaseStringType

@ondrejmirtes ondrejmirtes merged commit 7324328 into phpstan:2.1.x Feb 5, 2026
456 of 458 checks passed
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

@takaram takaram deleted the improve_microtime branch February 5, 2026 16:28
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.

5 participants