Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropertyHook with inline function adds double semicolon #1074

Open
Justinas-Jurciukonis opened this issue Mar 2, 2025 · 1 comment
Open

Comments

@Justinas-Jurciukonis
Copy link

I have following code to add Property Hook:

    private function licensePlanPriceLicensePlan(Property $property): void
    {
        $content = <<< PHP
        \$this->licensePlanPeriod?->licensePlan;
        PHP;

        $content = $this->parseContent($content)[0];

        $property->addHook(new PropertyHook('get', $content));
    }

    private function parseContent(string $content): array
    {
        $content = '<?php' . PHP_EOL . $content;

        return new ParserFactory()->createForHostVersion()->parse($content);
    }

When using inline function, the following output is generated in PrettyPrinter@850 with double ;

    public ?LicensePlan $licensePlan {
        get => $this->licensePlanPeriod?->licensePlan;;
    }

Am I doing something wrong here, or does pPropertyHook should either trim ; or do not add additional ;?

@nikic
Copy link
Owner

nikic commented Mar 2, 2025

See

/** @var null|Expr|Stmt[] Hook body */
. The body for a hook can either be a single expression, or an array of statements. You are passing a single statement. You should either pass without the [0] or use [0]->expr.

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

No branches or pull requests

2 participants