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

Closure export not working #37

Closed
reinfi opened this issue Feb 20, 2025 · 2 comments
Closed

Closure export not working #37

reinfi opened this issue Feb 20, 2025 · 2 comments

Comments

@reinfi
Copy link
Contributor

reinfi commented Feb 20, 2025

The following array does not work.

'external_services' => [
        'hotel' => [
            'campaign_matcher' => static fn (?DeviceOutput $deviceOutput): string => match ($deviceOutput) {
                DeviceOutput::Mobile => 'a',
                DeviceOutput::App, DeviceOutput::TabletApp => 'b',
                default => 'c',
            },
        ],
    ],

Error: Syntax error, unexpected T_DOUBLE_ARROW on line 14

The reason is that in the ClosureExporter the PHP-Parser is used for an old PHP version.

https://github.com/brick/varexporter/blob/master/src/Internal/ObjectExporter/ClosureExporter.php#L71

If this would be simply changed to it works.

$this->parser = (new ParserFactory)->createForHostVersion());

Any objections on changing this so it will understand new syntax easily?

@BenMorel
Copy link
Member

Hi, I think you're right, it should probably be createForHostVersion()!

Can you open a PR with this change, and a test case?

@reinfi reinfi changed the title Close export not working Closure export not working Feb 20, 2025
@BenMorel
Copy link
Member

Fixed in #38 and released in 0.6.0! Thank you.

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