Jnr PHP/Codeigniter Developer Interview Preparation Guide
Download PDF

Jnr PHP/Codeigniter Developer Frequently Asked Questions in various Jnr PHP/Codeigniter Developer job interviews by interviewer. The set of questions are here to ensures that you offer a perfect answer posed to you. So get preparation for your new job interview

61 Jnr PHP/Codeigniter Developer Questions and Answers:

1 :: Tell us what helpers in CodeIgniter are and how you can load a helper file?

In CodeIgniter, helpers are group of function in a particular category that assist you to perform specific functions. In CodeIgniter, you will find many helpers like URL helpers- helping in creating links, Text helpers- perform various text formatting routines, Cookies- helpers set and read cookies. You can load helper file by using command $this->load->helper (‘name’) ;

2 :: Do you know what is inhibitor in CodeIgniter?

For CodeIgniter, inhibitor is an error handler class, using the native PHP functions like set_exception_handler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.

3 :: Tell me how you can enable CSRF (Cross Site Request Forgery) in CodeIgniter?

You can activate CSRF (Cross Site Request Forgery) protection in CodeIgniter by operating your application/config/config.php file and setting it to

$config [ ‘csrf_protection’] = TRUE;

If you avail the form helper, the form_open() function will insert a hidden csrf field in your forms automatically

4 :: Do you know how can you enable error reporting in PHP?

Check if “display_errors” is equal “on” in the php.ini or declare “ini_set('display_errors', 1)” in your script.
Then, include “error_reporting(E_ALL)” in your code to display all types of error messages during the script execution.

Enabling error messages is very important especially during the debugging process as one can instantly get the exact line that is producing the error and can see also if the script in general is behaving correctly.

5 :: Explain me how would you declare a function that receives one parameter name hello?

If hello is true, then the function must print hello, but if the function doesn’t receive hello or hello is false the function must print bye.

function showMessage($hello=false){
echo ($hello)?'hello':'bye';

6 :: Do you know what are SQL Injections, how do you prevent them and what are the best practices?

SQL injections are a method to alter a query in a SQL statement send to the database server. That modified query then might leak information like username/password combinations and can help the intruder to further compromise the server.

To prevent SQL injections, one should always check & escape all user input. In PHP, this is easily forgotten due to the easy access to $_GET & $_POST, and is often forgotten by inexperienced developers. But there are also many other ways that users can manipulate variables used in a SQL query through cookies or even uploaded files (filenames). The only real protection is to use prepared statements everywhere consistently.

Do not use any of the mysql_* functions which have been deprecated since PHP 5.5 ,but rather use PDO, as it allows you to use other servers than MySQL out of the box. mysqli_* are still an option, but there is no real reason nowadays not to use PDO, ODBC or DBA to get real abstraction. Ideally you want to use Doctrine or Propel to get rid of writing SQL queries all together and use object-relational mapping which binds rows from the database to objects in the application.

7 :: Explain me what do you call the constructor of a parent class?

Just simply by parent::constructor() in an inherited class constructor.

8 :: Tell us how do you create a persistent cookie in php?

Cookies will only persist for the time you define. To do it for 1 year you can simply do:

setcookie( "cookieName", 'cookieValue', strtotime( '+1 year' ) ); //set for 1 year

9 :: Tell me are objects in PHP 5+ passed by value or reference?

This is a tricky question. To understand it, you need to understand how objects are instantiated.

10 :: Please explain what is the main problem in comparison of floating point numbers?

Explain the starship operator and why it returns the given output

echo 1.5 <=> 2.5; // -1
echo "a" <=> "a"; // 0
echo [1, 2, 3] <=> [1, 2, 4]; // -1