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 Call As Default

<?php

class Foo {
    const  BAR = strlen(...);

    function f($arg = strtolower(...)) { 
        return $arg;
    }
}

?>

Constant static expressions are used for constant and default values for parameters and properties. They have strict rules, and must be processed statically, before PHP executes the code. This means that it is not possible to call a function, which belongs exclusively to the execution phase of PHP.

Yet, since PHP 8.4, it is possible to see function names appears in that location: strlen(...) seems to be a forbidden syntax.

In fact, closures may be used to build default value, and one of the way to build them is to use the first class callable structure: that is when the function call includes the ellipsis operator .... So, in the end, it is not a functioncall, but a closure.

See Also

PHP Features

Last updated: 09 November 2026