Skip to content

Incorrect warning Variable $var is undefined. #299

Closed
@bnoordsij

Description

@bnoordsij

v2.11.13 works, but since v2.11.14 the following code gives 2 warnings:

 15 | WARNING | Variable $item is undefined.
 21 | WARNING | Variable $value is undefined.
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Admin;

use App\Entities\Vacancy;

class VacancyController
{
    public function index(): array
    {
        $first = Vacancy::query()->where(static fn ($query) => $query)->first(); // OK

        $val = static fn ($item): string => $item; // fails

        return [
            'first' => $first,
            'val' => $val,
            'fn1' => static fn ($val): string => $val, // OK (because $val exists)
            'fn2' => static fn (Vacancy $value): Vacancy => $value, // fails
        ];
    }
}

only the first arrow function reaches the last return in getArrowFunctionOpenClose

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions