[{"id":"phpintermediate-001","courseId":"php-intermediate","domain":"types-and-operators","topic":"Type juggling in comparisons","prompt":"After this code runs, var_dump($count) prints int(3), because the == comparison changed $count into an integer.","hint":"Ask whether converting a value for one operation also rewrites the variable that holds it.","explain":"PHP can read a value as a different type when an operator needs that type. The useful question is whether that reading is saved back into the variable.","source":"https://www.php.net/manual/en/language.types.type-juggling.php","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The comparison reads \"3\" as a number, but the stored value stays a string."},{"id":"b","text":"False","why":"A conversion made for a comparison does not change the value itself, so var_dump still prints string(1) \"3\"."}],"answer":"b","explanation":"When a value is interpreted as a different type, the value itself does not change types.","concept":"When a value is interpreted as a different type, the value itself does not change types.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"$count = \"3\";\nif ($count == 3) {\n    echo \"matched\";\n}\nvar_dump($count);","takeaways":["A comparison can read a string as a number without storing the number."]},{"id":"phpintermediate-002","courseId":"php-intermediate","domain":"types-and-operators","topic":"Numeric and leading-numeric strings","prompt":"On PHP 8.0 or later, a teammate runs this line. What happens?","hint":"Look at how the string starts, and what PHP reports for that kind of string.","explain":"A string used in arithmetic can be fully numeric, numeric only at its start, or not numeric at all. Each case gives a different number and a different kind of diagnostic.","source":"https://www.php.net/manual/en/language.types.numeric-strings.php","interaction":{"type":"single"},"options":[{"id":"a","text":"$total becomes int 1, because the string is not a valid number","whyNot":"PHP uses the leading 10 instead of discarding the string, so the sum is 11."},{"id":"b","text":"A TypeError is thrown, because the string contains words","whyNot":"TypeError is for strings that are not numeric at all, like \"bob3\"; this one starts with a number."},{"id":"c","text":"$total becomes int 11, and a warning is raised","why":"The string starts with 10, so PHP uses that number, and PHP 8 raises E_WARNING for the trailing text."},{"id":"d","text":"$total becomes int 11 with no message at all","whyNot":"PHP 8 still reports the trailing text; silence applied only before PHP 7.1."}],"answer":"c","explanation":"In PHP 8, a leading-numeric string such as \"10 Small Pigs\" is used as its leading number with an E_WARNING, while a non-numeric string throws a TypeError.","concept":"In PHP 8, a leading-numeric string such as \"10 Small Pigs\" is used as its leading number with an E_WARNING, while a non-numeric string throws a TypeError.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"$total = 1 + \"10 Small Pigs\";","takeaways":["Trailing text after a number gives a warning in PHP 8, not a silent result."]},{"id":"phpintermediate-003","courseId":"php-intermediate","domain":"types-and-operators","topic":"Integer overflow to float","prompt":"Which TWO statements about this code are correct on a 64-bit PHP 8 build?","hint":"Check what PHP does when a number no longer fits in an int.","explain":"Integers have a fixed range on each platform, with PHP_INT_MAX as the top of it. Think about which type a number that passes that range would need to be stored in.","source":"https://www.php.net/manual/en/language.types.integer.php","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The first var_dump prints a float, because the literal is beyond the int range.","why":"PHP interprets a number beyond the bounds of the int type as a float instead."},{"id":"b","text":"Both lines print int values, because PHP stores every whole number as an int.","whyNot":"Whole numbers past the int limit become floats; PHP does not store every whole number as an int."},{"id":"c","text":"The second var_dump prints float(9.2233720368548E+18), not an int.","why":"An operation whose result is beyond the int range returns a float, which on 64-bit systems prints as that value."},{"id":"d","text":"The second line wraps around and prints a large negative int, as in C.","whyNot":"An operation past the int range returns a float instead, so there is no wrap-around."},{"id":"e","text":"The script stops with a fatal error on line 1, because the literal is too large.","whyNot":"The literal is read as a float, and the manual's example prints it without any error."},{"id":"f","text":"PHP has unsigned ints, so the second line prints a positive int above PHP_INT_MAX.","whyNot":"PHP does not support unsigned int types, so no int above PHP_INT_MAX exists."}],"answer":"ac","explanation":"A number beyond the int range is read as a float, and an arithmetic result beyond that range returns a float instead.","concept":"A number beyond the int range is read as a float, and an arithmetic result beyond that range returns a float instead.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"$big = 50000000000000000000;\nvar_dump($big);\nvar_dump(PHP_INT_MAX + 1);","takeaways":["Check PHP_INT_MAX before assuming an arithmetic result is still an int."]},{"id":"phpintermediate-004","courseId":"php-intermediate","domain":"types-and-operators","topic":"Null coalescing operator ??","prompt":"After this code runs, what value does $retries hold?","hint":"Think about which values the operator treats as missing.","explain":"The null coalescing operator takes its left value unless that value is null, in which case it takes the right one. Consider which values count as null.","source":"https://www.php.net/manual/en/language.operators.comparison.php","interaction":{"type":"single"},"options":[{"id":"a","text":"3, because ?? falls back to the right side for any falsy value","whyNot":"The operator checks only for null, so a falsy value such as 0 is kept."},{"id":"b","text":"0, because the left side is not null, so it is kept","why":"The ?? operator uses the right side only when the left side is null, and 0 is not null."},{"id":"c","text":"An undefined index warning, with $retries left unset","whyNot":"The key exists here, and ?? never warns about a missing key either."},{"id":"d","text":"null, because a 0 value cancels the assignment","whyNot":"The assignment stores the result of ??, which is the left value 0, not null."}],"answer":"b","explanation":"The expression a ?? b evaluates to b only when a is null, otherwise to a, without a warning when a is missing.","concept":"The expression a ?? b evaluates to b only when a is null, otherwise to a, without a warning when a is missing.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"$settings = ['retries' => 0];\n$retries = $settings['retries'] ?? 3;","takeaways":["?? checks only for null, so 0, false and empty strings are kept."]},{"id":"phpintermediate-005","courseId":"php-intermediate","domain":"types-and-operators","topic":"Spaceship operator <=>","prompt":"A sort callback returns $a <=> $b for two numbers. What does that expression give back?","hint":"Think about what a sort needs to know about two values, not just whether they match.","explain":"Some comparison operators give only a yes or no. Others report more detail, which can be useful when sorting. Consider how much detail a sort needs.","source":"https://www.php.net/manual/en/language.operators.comparison.php","interaction":{"type":"single"},"options":[{"id":"a","text":"A bool, true only when $a is less than $b","whyNot":"That is how < behaves; <=> returns a three-way int instead."},{"id":"b","text":"An int equal to $a - $b, the exact gap between the two values","whyNot":"The result is only guaranteed to be less than, equal to, or greater than zero, not the size of the gap."},{"id":"c","text":"An int that is negative, zero or positive, depending on whether $a is less than, equal to or greater than $b","why":"The spaceship operator returns an int less than, equal to or greater than zero, which is what a sort callback needs."},{"id":"d","text":"A string: 'less', 'equal' or 'greater'","whyNot":"<=> returns an int, not a text label."}],"answer":"c","explanation":"The spaceship operator returns an int less than, equal to or greater than zero when the left operand is less than, equal to or greater than the right.","concept":"The spaceship operator returns an int less than, equal to or greater than zero when the left operand is less than, equal to or greater than the right.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"usort($prices, fn($a, $b) => $a <=> $b);","takeaways":["Sort callbacks only need the sign of the <=> result."]}]