PHP Interview Questions
There is given PHP interview questions and answers that have been asked in many companies. Let's see the list of top PHP interview questions.
What is the use of the final class and the final method in PHP?
The ‘final’ keyword, if present in a declaration, denotes that the current method does not support overriding by other classes. This is used when there is a requirement to create an immutable class.
Note: Properties cannot be declared as final. It is only methods and classes that get to be final.
Next up on this core PHP interview questions and answers blog, let us take a look at the intermediate questions.
.What are some of the popular frameworks in PHP?
There are many frameworks in PHP that are known for their usage. Following are some of them:
- CodeIgniter
- CakePHP
- Laravel
- Zend
- Phalcon
- Yii 2
What are the various constants predefined in PHP?
PHP consists of many constants, and following are some of the widely used ones:
- _METHOD_: Represents the class name
- _CLASS_: Returns the class name
- _FUNCTION_: Denotes the function name
- _LINE_: Denotes the working line number
- _FILE_: Represents the path and the file name
How to start displaying errors in PHP application?
Add following code in PHP.
ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL);
OR Add following code in .htacess
.php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on php_flag log_errors on
How to redirect https to HTTP URL and vice versa in .htaccess?
Redirect https to http
RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*)http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Redirect http to https
.RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$https://%{HTTP_HOST}/$1 [R=301,L]
How to set the header in CURL?
.curl_setopt( $ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
How array_walk function works in PHP?
It is used to update the elements/index of an original array.
In array_walk, two parameter are required.
original array and an callback function, with use of we update the array.
.What are encryption functions in PHP?
CRYPT() and MD5().
How we use ceil() and floor() function in PHP?
ceil() is use to find nearest maximum values of passing value.
Ceil Example:
$var= 6.5; $ans_var = ceil($var); echo $ans_var;
Output: 7
floor() is use to find nearest minimum values of passing value.
Floor Example:
$var= 6.5; $ans_var = floor($var); echo $ans_var;
Output: 6
.Why we use $_REQUEST variable?
We use $_REQUEST variable in PHP to collect the data_values from $_GET,$_POST and $_COOKIE variable.
.