PHP Interview Questions And Answers For Freshers

 What is PHP?

Answer # PHP: Hypertext Preprocessor is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. 12) What is a session in PHP? Answer # PHP 5 Sessions – A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer.   24) How long does a session last in PHP? Answer # This is the one. The session will last for 1440 seconds (24 minutes).   28) How does cookies work in PHP? Answer # A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.   30) What is the use of session and cookies in PHP? Answer # A session is a global variable stored on the server. Each session is assigned a unique id which is used to retrieve stored values. Sessions have the capacity to store relatively large data compared to cookies. The session values are automatically deleted when the browser is closed.

What are different types of errors available in Php ?

There are 13 types of errors in PHP, We have listed all below

  • E_ERROR: A fatal error that causes script termination.
  • E_WARNING: Run-time warning that does not cause script termination.
  • E_PARSE: Compile time parse error.
  • E_NOTICE: Run time notice caused due to error in code.
  • E_CORE_ERROR: Fatal errors that occur during PHP initial startup. (installation)
  • E_CORE_WARNING: Warnings that occur during PHP initial startup.
  • E_COMPILE_ERROR: Fatal compile-time errors indication problem with script.
  • E_USER_ERROR: User-generated error message.
  • E_USER_WARNING: User-generated warning message.
  • E_USER_NOTICE: User-generated notice message.
  • E_STRICT: Run-time notices.
  • E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
  • E_ALL: Catches all errors and warnings.

 

How to get length of an array in PHP ?

PHP count function is used to get the length or numbers of elements in an array

<?php
// initializing an array in PHP
$array=['a','b','c'];
// Outputs 3 
echo count($array);
?>

  What are the encryption functions available in PHP ?

crypt(), Mcrypt(), hash() are used for encryption in PHP.   

What is Cross-site scripting? Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications. XSS enables attackers to inject client-side script into web pages viewed by other users. A cross-site scripting vulnerability may be used by attackers to bypass access controls such as the same-origin policy.  

What are the difference between echo and print?

Difference between echo and print in PHP

echo in PHP

  • echo is language constructs that display strings.
  • echo has a void return type.
  • echo can take multiple parameters separated by comma.
  • echo is slightly faster than print.

Print in PHP

  • print is language constructs that display strings.
  • print has a return value of 1 so it can be used in expressions.
  • print cannot take multiple parameters.
  • print is slower than echo.

 

Leave a Reply

Your email address will not be published.