Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

FUNCTION In Closure Changed

When using the magic constant __FUNCTION__ inside a closure, the content used to be the {closure} string only. Since PHP 8.4, it also includes the name of the original file, and the line number, so as to identify the origin source code.

PHP code

<?php

$foo = fn() => __FUNCTION__;

$closure = function() { return __FUNCTION__;};

echo $foo();

echo $closure();


?>

Before

{closure}{closure}

After

{closure:/codes/magicConstantInClosure.php:3}{closure:/codes/magicConstantInClosure.php:5}

PHP version change

This behavior changed in 8.4.

Extension

© 2023-2026, Damien Seguy - Exakat