Consider this PHP code with strict typing enabled. What will it output?
<?php declare(strict_types=1); function addInts(int $a, int $b): int { return $a + $b; } echo addInts(5, '10');
Strict typing enforces exact types for function parameters.
With strict typing enabled, passing a string where an int is expected causes a TypeError.
What will this PHP code output when strict typing is not enabled?
<?php function addInts(int $a, int $b): int { return $a + $b; } echo addInts(5, '10');
Without strict typing, PHP tries to convert types automatically.
PHP converts the string '10' to integer 10 automatically, so the sum is 15.
What error will this code produce when strict typing is enabled?
<?php declare(strict_types=1); function greet(string $name): string { return 'Hello, ' . $name; } echo greet(123);
Check the type of argument passed to the function.
Strict typing requires the argument to be a string. Passing an integer causes a TypeError.
Which of the following is the best reason to enable strict typing in PHP?
Think about how strict typing affects error detection.
Strict typing forces exact types, so bugs from wrong types are caught early, improving code safety.
Given strict typing is enabled, what will this code output?
<?php declare(strict_types=1); function multiply(float $a, float $b): float { return $a * $b; } $result = multiply(3, 2.5); echo gettype($result) . ': ' . $result;
Check how PHP handles integers passed to float parameters with strict typing.
PHP allows int to float conversion in strict mode for parameters typed as float, so result is float 7.5.