Php interview questions

Questions : 1  

Php interview questions

How we load all classes that placed in different directory in one PHP File , means how to do auto load classes, 

Answer :  by using spl_autoload_register(‘autoloader::function’); Like below class autoloader { public static function moduleautoloader($class) { $path = $_SERVER[‘DOCUMENT_ROOT’] . “/modules/{$class}.php”; if (is_readable($path)) require $path; } public static function daoautoloader($class) { $path = $_SERVER[‘DOCUMENT_ROOT’] . “/dataobjects/{$class}.php”; if (is_readable($path)) require $path; } public static function includesautoloader($class) { $path = $_SERVER[‘DOCUMENT_ROOT’] . “/includes/{$class}.php”; if (is_readable($path)) require $path; } } spl_autoload_register(‘autoloader::includesautoloader’); spl_autoload_register(‘autoloader::daoautoloader’); spl_autoload_register(‘autoloader::moduleautoloader’);
Questions : 2 How many types of Inheritances used in PHP and how we achieve it

Php interview questions

Answer :  As far PHP concern it only support single Inheritance in scripting. we can also use interface to achieve multiple inheritance.
Questions : 3 PHP how to know user has read the email?

Php interview questions
Answers :  Using Disposition-Notification-To: in mailheader we can get read receipt. Add the possibility to define a read receipt when sending an email. It’s quite straightforward, just edit email.php, and add this at vars definitions: var $readReceipt = null; And then, at ‘createHeader’ function add: if (!empty($this->readReceipt)) { $this->__header .= ‘Disposition-Notification-To: ‘ . $this->__formatAddress($this->readReceipt) . $this->_newLine; }
Questions :4 What are default session time and path? 

Php interview questions
Answers :  default session time in PHP is 1440 seconds or 24 minutes Default session save path id temporary folder /tmp
Questions : 5 how to track user logged out or not? when user is idle ?
Answers :  By checking the session variable exist or not while loading th page. As the session will exist longer as till browser closes. The default behaviour for sessions is to keep a session open indefinitely and only to expire a session when the browser is closed. This behaviour can be changed in the php.ini file by altering the line session.cookie_lifetime = 0 to a value in seconds. If you wanted the session to finish in 5 minutes you would set this to session.cookie_lifetime = 300 and restart your httpd server.
Questions : 6 how to track no of user logged in ?

Php interview questions
Answers :  whenever a user logs in track the IP, userID etc..and store it in a DB with a active flag while log out or sesion expire make it inactive. At any time by counting the no: of active records we can get the no: of visitors.
Questions : 7 in PHP for pdf which library used?
Answers :  The PDF functions in PHP can create PDF files using the PDFlib library With version 6, PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4. There is also the » Panda module. FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.
Questions : 8 for image work which library?
Answers :  we will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.
Questions : 9 what is design pattern? singleton pattern?
Answers :  A design pattern is a general reusable solution to a commonly occurring problem in software design. The Singleton design pattern allows many parts of a program to share a single resource without having to work out the details of the sharing themselves.
Questions : 10 what are magic methods?
Answers :  Magic methods are the members functions that is available to all the instance of class Magic methods always starts with “__”. Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone()

for jobs : click here

Frequently asked MNC – Interview Questions & Tutorials