(int) And (ant)¶
<?php
const INT = static function($x) {return (int)$x * (int)$x;};
echo (int)(" 123s ");
// fatal error
// echo ((int))(" 123s ");
const ant = static function($x) {return (int)$x * (int)$x;};
echo (ant)(" 123s ");
echo ((ant))(" 123s ");
It is possible to store a Closure in a constant, since PHP 8.5. This means that the closure has to be called by storing the constant in parenthesis: this way, PHP first extracts the value of the constant, then, calls the closure.
There is something else that is between parenthesis: a cast. And cast has a very high priority. So, when a int constant is created, it still calls the cast, and ignores the constant.
May be constants should not be called as casts?
See Also¶
Of int and ant [Try me]
PHP Error Messages¶
PHP Features¶
Last updated: 14 July 2026