Complete the code to enable strict typing in PHP.
<?php [1] function add(int $a, int $b): int { return $a + $b; } echo add(5, 10);
In PHP, to enable strict typing, you must add declare(strict_types=1); at the top of the file.
Complete the function call to cause a type error when strict typing is enabled.
<?php declare(strict_types=1); function multiply(int $x, int $y): int { return $x * $y; } // This will cause a type error $result = multiply([1], 5); echo $result;
When strict typing is enabled, passing a string like "10" to a function expecting an int causes a type error.
Fix the error by completing the function parameter type declaration.
<?php declare(strict_types=1); function greet([1] $name): string { return "Hello, $name!"; } echo greet("Alice");
The function expects a string parameter for the name. Using string as the type fixes the error.
Fill both blanks to create a function that returns the sum only if both inputs are integers.
<?php declare(strict_types=1); function safeAdd([1] $a, [2] $b): int { return $a + $b; } echo safeAdd(3, 7);
Both parameters must be typed as int to ensure strict typing and correct addition.
Fill all three blanks to create a function that returns the uppercase version of a string if it is not empty.
<?php declare(strict_types=1); function shout([1] $text): string { if ($text [2] '') { return strtoupper([3]); } return ''; } echo shout('hello');
The function parameter is typed as string. The condition checks if $text !== '' (not empty). Then it returns the uppercase of $text.