Complete the code to create a first-class callable from the function strlen.
<?php $func = [1](...); echo $func('hello'); ?>
In PHP 8.1+, to create a first-class callable from a function, use the function name without quotes or parentheses, followed by (...).
Complete the code to create a first-class callable from the function strtoupper using the callable syntax.
<?php $func = [1](...); echo $func('hello'); ?>
The first-class callable syntax for functions uses just the function name without quotes or parentheses, followed by (...).
Complete the code to create a first-class callable from the static method MyClass::myMethod.
<?php class MyClass { public static function myMethod() { return 'Hello'; } } $callable = [1](...); echo $callable(); ?>
For static methods, the first-class callable syntax uses the class name, ::, and method name without quotes or parentheses, followed by (...).
Fill both blanks to create a first-class callable from an instance method myMethod of $obj.
<?php class MyClass { public function myMethod() { return 'Hi'; } } $obj = new MyClass(); $callable = [1]->[2](...); echo $callable(); ?>
To create a first-class callable for an instance method, use $object->method(...) with the bare method name (no quotes).
Fill all three blanks to create a first-class callable from a closure stored in $closure and call it with argument 'world'.
<?php $closure = fn($name) => "Hello, $name!"; $callable = [1]; echo $callable([2]); // Using first-class callable syntax $callable2 = [3]; echo $callable2('world'); ?>
(...) for first-class syntax.Assign the closure variable directly as it's already callable. Call it with the string argument. Use $closure(...) for explicit first-class callable syntax.