15 extra multiple-choice questions for PHP: Hypertext Preprocessor (12th Standard Computer Applications, Samacheer Kalvi), beyond the ones printed in the textbook — each with the correct option highlighted and a clear, worked explanation. Free to read in English and Tamil.
Q1
Who created the PHP scripting language in 1994?
- A. Rasmus LerdorfCorrect
- B. Tim Berners-Lee
- C. Ed Guilbert
- D. Paul Mockapetris
Explanation. PHP was created by Rasmus Lerdorf in the year 1994 as a server-side scripting language.
Q2
Which of the following describes why PHP is classified as an interpreted language?
- A. It must be compiled into an executable file before running.
- B. PHP files are interpreted line by line by the web server.Correct
- C. It runs entirely within the client's web browser without server interaction.
- D. It requires a database connection to parse any static text.
Explanation. PHP is an interpreted language, which means there is no need to compile it; instead, PHP files are processed line by line by the web server.
Q3
Which of the following is an invalid variable name in PHP because it contains an illegal special character?
- A. \$my_report1
- B. \$_hidden
- C. \$full-nameCorrect
- D. \$age
Explanation. Variable names in PHP can contain letters, numbers, and underscores, but cannot contain hyphens. Hence, \$full-name is invalid.
Q4
If a PHP script declares \$name = "Balu"; and later attempts to output \$Name, what will occur?
- A. It outputs "Balu" because variable names are case-insensitive.
- B. It references a completely different, uninitialized variable because variable names are case-sensitive.Correct
- C. The script fails to run due to a syntax error.
- D. It automatically converts the string to uppercase.
Explanation. Variable names in PHP are case-sensitive. Therefore, \(name and \)Name are treated as entirely different variables.
Q5
Which PHP data type represents a connection to an external database or file?
- A. Object
- B. ResourceCorrect
- C. NULL
- D. Array
Explanation. A resource is a special type of data in PHP that represents a connection to an external resource, such as a file handle or a database connection.
Q6
Which of the following is true regarding the case sensitivity of the NULL keyword in PHP?
- A. The keyword NULL is strictly case-sensitive and must be uppercase.
- B. The keyword NULL is not case-sensitive.Correct
- C. NULL must be enclosed in double quotes to be valid.
- D. NULL is case-sensitive only when used in double quotes.
Explanation. Unlike variable names, the NULL keyword in PHP is not case-sensitive, meaning null and NULL represent the same value.
Q7
Which of the following statements is true about using parentheses with the PHP echo statement?
- A. Parentheses are strictly required around arguments.
- B. Parentheses are not required but using them will not cause an error.Correct
- C. Echo statements never accept parentheses.
- D. Parentheses are required only when outputting multiple string arguments.
Explanation. In PHP, the echo statement does not require parentheses around its arguments, but using them is allowed and will not cause an error.
Q8
To safely output a string of text that contains a single quote using the echo statement, which of the following is recommended?
- A. Enclose the entire string in single quotes.
- B. Enclose the entire string in double quotes.Correct
- C. Omit the semicolon at the end of the statement.
- D. Precede the entire echo statement with a hash symbol.
Explanation. To output a string containing a single quote, double quotes can be used to enclose the string, ensuring the single quote is treated as a literal character.
Q9
If you compare 5 === 5.0 in PHP, what is the returned result and why?
- A. True, because they have equivalent mathematical values.
- B. False, because they are not of the same data type.Correct
- C. True, because the double equals operator is identical.
- D. False, because the values are mathematically different.
Explanation. The identical operator (===) returns True only if both operands are equivalent and of the same data type. Since 5 is an integer and 5.0 is a float, it returns False.
Q10
How does the logical XOR operator work in PHP?
- A. It returns true if both operands are true.
- B. It returns true if at least one of the operands is true.
- C. It returns true if exactly one of the operands is true.Correct
- D. It returns true only if both operands are false.
Explanation. The logical XOR operator returns true if exactly one of the two operands is true, and false if both are true or both are false.
Q11
In PHP, what is the behavior of the post-increment operator (\$a++)?
- A. First, \$a is incremented by 1, and then the new value is returned.
- B. First, the current value of \$a is returned, and then it is incremented by 1.Correct
- C. It decrements \$a by 1 before returning the value.
- D. It multiplies \$a by 1 and returns the same value.
Explanation. The post-increment operator (\$a++) first returns the original value of the variable and then increments the variable's value by 1.
Q12
Which of the following is the string concatenation operator in PHP?
- A. +
- B. .Correct
- C. &
- D. ,
Explanation. In PHP, a single dot (.) is used as the concatenation operator to join two or more strings together.
Q13
Where are PHP scripts executed in a typical web application setup?
- A. On the client's computer inside the web browser.
- B. On the server side, before the output is sent to the client.Correct
- C. Within the database engine exclusively.
- D. By the client's operating system as a background service.
Explanation. PHP scripts are executed on the web server. The web server passes the PHP code to the PHP interpreter, and only the generated HTML output is sent back to the client's browser.
Q14
Which of the following can be used to initiate a single-line comment in PHP?
- A. /*
- B. // or #Correct
- C.