100 PHP’s possible interview questions and answers for fresher-part 4

  • Home -
  • 100 PHP’s possible interview questions and answers for fresher-part 4

61) In a class object pattern, where is : : ‘scrape resolution’ used?

In class object pattern we can use scope resolution at two places.
For access static methods that do not require object initialization.
And for calling parent class constructor.

62) What is SQLinjection ?.

SQL injection is technique through which malicious code is placed inside SQL data. It entersvia poor scripting to SQL databases. Good scripting and PHPs PDO areoptions to prevent SQLinjection.

63) How we call a parent constructor in PHP?

First, parent constructor is not called in the child class directly; we have to call it specifically.
parent::constructor ($value)

64) How to send email using php?

There is built in PHP function for sending email.mail() is the function name which takes few parameters for sending email. The first parameter is ‘to’ and second parameter is subject and third parameter is’ headers’.

65) What are super global variables in PHP?

There are few variables which are built-in in PHP and these are called global variables.
$GLOBALS
$_SERVER
$_REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION

66) What is session in PHP?

Session is a way of storing data into server and fetching it from server to client computer.
Using session, we can store data which will be accessible to across the website. Once browser is closed, session data is lost.

67) Howto initialize the session in any page?

session_start() is the function which we must write in the beginning of the PHP page to initialize session.

68) What is default session time and path in PHP. How to change it ?

The default session time is 24 minutes or 1440 seconds. Default session storage path is /temp folder.

69) What is difference between session_unset() and session_destroy()

session_unset :This removes the session variables and does not delete the session data.

session_start();
session_unset();
$a = “1234”;
$_SESSION[a] = $a;
Output : 1234
session destroy : This deleted the session data. The complete session.

session_start();
session_destroy();
$a = “1234”;
$_SESSION[a] = $a;
$_SESSION[a] is NULL.

70) When do sessions end?

Sessions automatically end when the PHP script finishes executing but can be manually ended using the session_write_close().

71) What is the difference between session_unregister() and session_unset()?

The session_unregister() function deregister a global variable from the current session and the session_unset() function frees all session variables.
session_unregister has been deprecated after PHP 5.x version.

72) What is $_REQUEST variable for?

$_REQUEST is the combination of $_POST, $_GET and $_COOKIES. Any of these content can be fetch using $_REQUEST global variable.

73) How can you get theurl from where the visitor has visited the page?

$_SERVER[‘HTTP_REFERER’] is the global variable using which we can get the url of referring page.

74) What does $_FILES means?

$_FILES sends file related information data in an associate array format. To work with this global variable, we must include enctype=”multipart/form-data” in the HTML form.

75) Why we use $_FILES[‘image][‘tmp_name’] in PHP?

Before uploading the file to actual server destination, first the file is stored in local computer’s temporary directory, usually in ‘temp’ folder. So, we get temp file name using $_FILES[‘image][‘tmp_name’] for uploading the file because the move_uploaded_file() function takes two parameters. The first parameter is temp name of image/file.

76) How can we catch the error while uploading the file?

$_FILES[file_name][‘error’] contains the error code along with the uploaded file.

77) How can we change the maximum size of the files to be uploaded?

We need to change the maximum file size value in php.ini. One can find this into PHP.ini upload_max_filesize.

78) What is PDO?

PDO is acronym of PHP ObjectData .It is a database access layer providing a uniform method of access to multiple databases. It uses prepared statements which is less vulnerable for malicious code into database.

79) What is COOKIESin PHP?

Cookies are a simple text file which is stored in client’s computer with some information like user name, password and expiry etc.

80) Where @ is used in PHP?

@ is used supress the error. If @ is placed before the statement then runtime error is handled by PHP.