PHP Interview Question Answer For Experienced
Q- Which PHP Extension Helps To Debug The Code?
The name of that Extension is Xdebug. It uses the DBGp debugging protocol for debugging. It is highly configurable and adaptable to a variety of situations.Xdebug provides the following details in the debug information.Stack and function trace in the error messages.
Full parameter display for user-defined functions.
It displays function name, file name and line indications where the error occurs.
Support for member functions.
Protection for infinite recursions
Xdebug also provides.Profiling information for PHP scripts.
Code coverage analysis.
Capabilities to debug your scripts interactively with a front-end debugger.
Xdebug is also available via PECL. Q-What Is The Use Of Urlencode() And Urldecode() In PHP?
The use of urlencode() is to encode a string before using it in a query part of a URL. It encodes the same way as posted data from a web page is encoded. It returns the encoded string.Following is the Syntax.urlencode (string $str )
It is a convenient way for passing variables to the next page.The use of urldecode() function is to decode the encoded string. It decodes any %## encoding in the given string (inserted by urlencode.)Following is the Syntax.urldecode (string $str ) Q- What Is The Difference Between Split And Explode Functions For String Manipulation In PHP?
Both of them perform the task of splitting a String. However, the method they use is different.The split() function splits the String into an array using a regular expression and returns an array.For Example.split(:May:June:July);
Returns an array that contains May, June, July.The explode() function splits the String using a String delimiter.For Example.explode(and May and June and July);
Also returns an array that contains May, June, July.Q- How To Get The Information About The Uploaded File In The Receiving Script?
Once the Web server receives the uploaded file, it calls the PHP script specified in the form action attribute to process it.This receiving PHP script can get the information of the uploaded file using the predefined array called $_FILES. PHP arranges this information in $_FILES as a two-dimensional array. We can retrieve it as follows.$_FILES[$fieldName][‘name’] – It represents the file name on the browser system.
$_FILES[$fieldName][‘type’] – It indicates the file type determined by the browser.
$_FILES[$fieldName][‘size’] – It represents the size of the file in bytes.
$_FILES[$fieldName][‘tmp_name’] – It gives the temporary filename with which the uploaded file got stored on the server.
$_FILES[$fieldName][‘error’] – It returns the error code associated with this file upload.
The $fieldName is the name used in the ”>.Q- What Does The Presence Of The Operator ‘::’ Represent?
It gets used to access the static methods that do not require initializing an object.Q- What Is PDO In PHP?
PDO stands for .It is a set of PHP extensions that provide a core PDO class and database, specific drivers.
It provides a vendor-neutral, lightweight, data-access abstraction layer. Thus, no matter what database we use, the function to issue queries and fetch data will be the same.
It focuses on data access abstraction rather than database abstraction.
PDO requires the new object-oriented features in the core of PHP 5. Therefore, it will not run with earlier versions of PHP.
PDO divides into two components.The core which provides the interface.
Drivers to access a particular driver.Q- What Are Different Ways To Get The Extension Of A File In PHP?
There are following two ways to retrieve the file extension.$filename = $_FILES[‘image’][‘name’];$ext = pathinfo($filename, PATHINFO_EXTENSION);$filename = $_FILES[‘image’][‘name’];$array = explode(‘.’, $filename);$ext = end($array); Q-6. What Is Autoloading Classes In PHP?
With autoloaders, PHP allows the last chance to load the class or interface before it fails with an error.The spl_autoload_register() function in PHP can register any number of autoloaders, enable classes and interfaces to autoload even if they are undefined.
In the above example, we do not need to include Class1.php and Class2.php. The spl_autoload_register() function will automatically load Class1.php and Class2.php.
Q- What Is The Default Timeout For Any PHP Session?
The default session timeout happens in 24 minutes (1440 seconds). However, we can change this value by setting the variable in [php.ini] file. Q-How Can We Display The Correct URL Of The Current Webpage? Answer <?php echo $_SERVER[‘PHP_SELF’]; ?>