Skip to content

SIGABRT/SIGTRAP when using closures in attributes in PHP 8.5 #17096

Closed
@alexandre-daubois

Description

@alexandre-daubois

Description

While playing with closures in attributes thanks to the last accepted RFC, the following code:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Core\Authorization\IsGrantedPayload;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class HomeController extends AbstractController
{
    #[Route(path: '/')]
    #[IsGranted(callable: static function (mixed $payload) {
        return $payload->authorizationChecker->isGranted('ROLE_ADMIN');
    })]
    public function home(): Response
    {
        return new Response('test');
    }
}

Resulted in this output (debug enabled during PHP compilation):

[PHP-FPM    ] Assertion failed: (0), function zend_ast_export_ex, file zend_ast.c, line 2636.
[PHP-FPM    ] Dec  9 16:31:19 |WARNING| FPM    [pool www] child 12292 exited on signal 6 (SIGABRT) after 10.539209 seconds from start

When debug is disabled, a SIGTRAP is thrown and PHP crashes immediately. The built-in server is used (php-src/sapi/cli/php -S localhost:8002 -t public/), Symfony CLI server behave the same. It crashes as soon as you go on /.

A plain Symfony project can be created, then create a controller with the above code snippet. The callable argument doesn't have to even exist in Symfony's IsGranted attribute (that's the feature I'm playing with). Even with a brand new Symfony install, this crashes.

This is the most minimal snippet I could do to reproduce this. If you need any other information to help you debug/setup the reproducer, I'd be happy to help.

PHP Version

PHP 8.5.0-dev

Operating System

macOS 15.1.1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions