Security · Question 3 of 12
A URL parameter uid contains the value "5 OR 1=1". What does (int)$uid return in PHP 8?
1 answer is correct. Easy
Show answer
Answer
- B 5
Explanation
The (int) cast converts a string to an integer and reads the leading digits: "5 OR 1=1" becomes 5, and the appended SQL part is dropped. If the text does not start with a number, such as "abc", the cast results in 0. This makes (int) a simple and effective sanitization for IDs before they are processed further. A TypeError only occurs with strictly typed function parameters, not with an explicit cast. Still, in SQL queries you pass numbers as named parameters too, for example with Connection::PARAM_INT.