1. What’s the difference between the include() and require() functions?
Answer: They both include a specific file but on require the process exits with a fatal error if the file can’t be included, while include statement may still pass and
jump to the next step in the execution.
2. How can we get the IP address of the client?
3. Find the output of the following
$a = ‘1’;
$b = &$a;
$b = “2$b”;
echo $a.”, “.$b;
Answer: 21, 21
4. What are the main error types in PHP?
Answer: In PHP there are three main type of errors:
Notices – These are non critical errors which does not hamper the execution of program. An example of a Notice would be accessing an undefined variable.
Warnings – More important errors than Notices, however the scripts continue
the execution. An example would be include() a file that does not exist.
Fatal – This type of error causes a termination of the script execution when it
occurs. An example of a Fatal error would be accessing a property of a nonexistent
object or require() a non-existent file.
5. What is the difference between GET and POST?
Answer: The information submitted through GET displays on the URL of the browser where POST information does not. GET can handle the the information of maximum 2048 characters but POST has no restrictions.
6. How can you enable error reporting in PHP?
Answer: By include “error_reporting(E_ALL)” in your code to display all types of
error messages during the script execution.
Also, we can enable the error reporting from php.ini file.
7. Find the output of the following
$i = 016;
echo $i / 2;
Answer: The Output should be 7. The leading zero indicates an octal number in PHP,
so the number evaluates to the decimal number 14 instead to decimal 16
8. Why would you use === instead of ==?
Answer: ‘===’ returns true if both values are of the same type.
9. Do you use Composer? If yes, what benefits have you found in it?
Answer: Using Composer is a tool for dependency management. You are able to
declare the libraries your product relies on and Composer will manage the
installation and updating of the libraries. The benefit is a consistent way of
managing the libraries you depend on and you will spend less time managing
the libraries you depend on in your project.
10. What are different type of sorting functions in PHP?
sort() – sort arrays in ascending order. asort() – sort associative arrays in
ascending order, according to the value.
ksort() – sort associative arrays in ascending order, according to the key.
arsort() – sort associative arrays in descending order, according to the
rsort() – sort arrays in descending order.
krsort() – sort associative arrays in descending order, according to the
array_multisort() – sort the multi dimension array.
usort()– Sort the array using user defined function.