PHP VERSION: 8.2.18

uniform_variable_syntax_callable.php

<?php 
// callable is immediately executed in PHP 7

class Foo
{
    const 
FOO_FORMAT 'Y-m-d H:i:s'
    public function 
bar()
    {
        return function () {
            
$date = new DateTime('now');
            return 
$date->format(Foo::FOO_FORMAT) . PHP_EOL;
        };
    }
}

$foo = new Foo();
// php 5.x
$callable $foo->bar();
echo 
$callable();
// php 7
echo $foo->bar()();

Output


2024-04-26 06:30:05
2024-04-26 06:30:05
SOURCE CODE