Skip to content

Incorrect type inference for CarbonImmutable::createFromFormat() returns DateTimeImmutable #3055

Description

@abcRede

Environment

  • Phpactor VS Code extension: 1.7.6
  • PHP: 8.5
  • Carbon: 3.13.0

Description

CarbonImmutable::createFromFormat() is inferred as returning DateTimeImmutable, causing a false positive diagnostic:

Method "startOfDay" does not exist on class "DateTimeImmutable"

phpactor(worse.missing_member)

Minimal reproduction

use Carbon\CarbonImmutable;

CarbonImmutable::createFromFormat('Y-m-d', '2026-01-01')
    ->startOfDay();

Actual result

The diagnostic reports:

Method "startOfDay" does not exist on class "DateTimeImmutable"

Expected result

The inferred type should be Carbon\CarbonImmutable, so startOfDay() should be recognized.

Additional information

The following methods work correctly and infer the proper Carbon type:

CarbonImmutable::now()->startOfDay();

CarbonImmutable::parse('2026-01-01')->startOfDay();

CarbonImmutable::createFromTimestamp(0)->startOfDay();

Screenshot:

Image

This suggests that Phpactor may be resolving the inherited DateTimeImmutable::createFromFormat() instead of Carbon's overridden implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions