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.

Certifications & exams

Which exam comes next?

You can already practise for 19 exams, and 21 are up for a vote. See all certifications with their official information, cast your vote or suggest your exam.

See all certifications