Top PHP Interview Questions And Answers in 2022

  1. What is PHP?

PHP is a widely-used server side scripting language that is especially suited for web development, creating dynamic websites and can be embedded into HTML.

  1. What does PHP stand for?

PHP stands for Hypertext Preprocessor.

  1. What is PEAR?

PEAR stands for PHP Extension and Application Repository and is widely used to provide a high level of programming for web programmers.

  1. What is the purpose of constant() function?

As indicated by the name, this function will return the value of the constant. This is useful when you want to retrieve value of a constant, but you do not know its name, i.e. It is stored in a variable or returned by a function.

  1. What is the process to run the smart PHP shell from the command line interface?

Basically use the PHP CLI program with the option like:

Php – a

  1. What are the privilege and the most two essential ways to initiate and execute a PHP bit of code?

The two most consistent ways to start and finish a PHP script are: <? Php [— PHP code— -]?> and <? [—PHP code — ]?>

  1. How can we demonstrate the output to the program?

To demonstrate the output to the program, use special tags <? = and?>.

  1. Is various heritages maintained in PHP?

PHP support single inheritance, it suggests that a class can be extended from only a child class using the catchphrase ‘created’.

  1. What is the difference between a final class and a final method?

Final is introduced in PHP5. Final class means that this class cannot be sub classed and a final method cannot be overridden.

PHP-questions-answer

  1. What type of operation is needed when passing values through a form or an URL?

If we would like to pass values through a form or an URL then we need to encode and to decode them using htmlspecialchars() and urlencode().

  1. How can I display text with a PHP script?

Two methods are possible:

<!–? Php echo “Method 1”; print “Method 2”;?–>

  1. How can PHP and JavaScript interact?

PHP and JavaScript cannot directly interact since PHP is a server side language and Javascript is a client side language. However we can exchange variables since PHP is able to generate Javascript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.

  1. What is needed to be able to use image function?

GD library is needed to be able execute image functions.

  1. What is the use of the function ‘imagetypes()’?

imagetypes() gives the image format and types supported by the current version of GD-PHP.

Interested in Learning PHP with Advanced Frameworks? Click Here

  1. How comparison of objects is done in PHP5?

We use the operator ‘==’ to test is two object are instanced from the same class and have same attributes and equal values. We can test if two object are referring to the same instance of the same class by the use of the identity operator ‘===’.

  1. How can PHP and HTML interact?

It is possible to generate HTML through PHP scripts, and it is possible to pass information from HTML to PHP.

  1. What is the main difference between require() and require_once()?

require() and require_once () perform the same task except that the second function checks if the PHP script is already included or not before executing it.

(Same for include_once() and include()

  1. What are the functions to be used to get the image’s properties (size, width and height)?

The functions are getimagesize() for size, imagesx() for width and imagesy() for height.

  1. How is it possible to set an infinite execution time for PHP script?

The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded’. It is also possible to specify this in the php.ini file.

  1. How failures in execution are handled with include() and require() functions?

If the function require() cannot access to the file then it ends with a fatal error. However, the include() function gives a warning and the PHP script continues to execute.

  1. How can we display information of a variable and readable by human with PHP?

To be able to display a human-readable result we use print_r().

  1. What does the PHP error ‘Parse error in PHP – unexpected T_variable at line x’ means?

This is a PHP syntax error expressing that a mistake at the line x stops parsing and executing the program.

  1. Define smarty?

Smarty is a template engine written in PHP. Normally, these templates will include variables —like {$variable} — and a range of logical and loop operators to enable adaptability within of the template.

  1. What is Memcache?

Memcache is a technique that caches objects in memory such that your web application can get to them really fast. It is used by sites such as Digg.com, Facebook.com and NowPublic.com and is widely recognized as an essential ingredient in scaling any LAMP.

  1. How can we execute a PHP script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program.

Get PHP Certification in just 20 Hours, Contact Now
  1. What is the purpose of _CLASS_ constant?

_CLASS_ − The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive).

  1. How will you find the length of a string in PHP?

The strlen() function is used to find the length of a string.

  1. How will you get environment variables in PHP?

PHP provides a function getenv() to access the value of all the environment variables.

  1. What is the purpse $_REQUEST variable?

The PHP $_REQUEST variable contains the contents of $_GET, $_POST, and $_COOKIE. The PHP $_REQUEST variable can be used to get the result form data sent with both the GET and POST methods.

  1. Can you assign the default values to a function parameters?

Yes, we can set a parameter to have a default value if the function’s caller does not pass it.

 

Save

Save

Save

Save

Add a Comment

Your email address will not be published. Required fields are marked *