Top 27 Php5 Interview Questions You Must Prepare 27.Jul.2024

Q1. What Function Should You Use To Join Array Elements With A Glue String?

implode

Q2. Which Is True About The Singleton Design Pattern?

A singleton pattern me that a class can have only one instance object.

Q3. Which Will Check If A Function Exists?

function_exists()

Q4. What Is The Best Practice For Running Mysql Queries In Php? Consider The Risk Of Sql Injection.

Use PDO prepared statements and parameterized queries: for example: $input= $_POST["user-input"] $stmt = $pdo->prepare('INSERT INTO table (column) VALUES (":input"); $stmt->execute(array(':input' => $input));

Q5. Which Is Incorrect With Respect To Separating Php Code And Html?

As PHP is a scripting language, HTML and PHP cannot be separated.

Q6. Which Is Used To Maintain The Value Of A Variable Over Different Pages?

session_register() is used to maintain the value of a variable over different pages.

Q7. Does Php 5 Support Exceptions?

Yes,PHP 5 supports Exceptions.

Q8. Which Is Not A File-related Function In Php?

fappend

Q9. What Is The Best Way To Change The Key Without Changing The Value Of A Php Array Element?

$arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]);

Q10. Which Will Start A Session?

session_start();

Q11. Which Is Useful For Method Overloading?

__call,__get,__set

Q12. Which Cryptographic Functions In Php Returns The Longest Hash Value?

sha1()

Q13. What Enctype Is Required For File Uploads To Work?

multipart/form-data

Q14. Which Function Can Be Used To Delete A File?

unlink

Q15. What Is The Correct Line To Use Within The Php.ini File, To Specify That 128mb Would Be The Maximum Amount Of Memory That A Script May Use?

memory_limit = 128M

Q16. What Is The Correct Syntax Of Mail() Function In Php?

mail ($to, $subject, $message,$headers)

Q17. Which Is Not A Php Magic Constant?

Time

Q18. What Is The Correct Php Command To Use To Catch Any Error Messages Within The Code?

set_error_handler('error_handler');

Q19. Which Methods Should Be Used For Sending An Email Using The Variables $to, $subject, And $body?

mail($to,$subject,$body)

Q20. What Would Occur If A Fatal Error Was Thrown In Your Php Program?

The PHP program will stop executing at the point where the error occurred.

Q21. Which Variable Declarations Within A Class Is Invalid In Php?

internal $term = 3;

Q22. Which Is The Correct Way To Check If A Session Has Already Been Started ?

if (session_id()) echo 'session started';

Q23. Which Is Correct About Mysqli And Pdo?

Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS.

Q24. What Is The String Concatenation Operator In Php?

( . )

Q25. Which Function Will Suitably Replace 'x' If The Size Of A File Needs To Be Checked? $size=x(filename);

filesize

Q26. Which Will Print Out The Php Call Stack?

var_dump($e->getTraceAsString());

Q27. Can Php Use Gettext?

Yes. We can use gettext in PHP.