Advanced PHP Interview Questions And Answers

PHP Interview Questions And Answers

PHP Interview Questions And Answers For Experienced 2018. Here in this article, we are providing a list of 135 real-time scenario based PHP interview questions for freshers and professionals. This list includes PHP interview questions for 1 year experience, 2 year experience, 3 year experience, 4 year experience, 5 year experienced PHP developers and experienced PHP programmers.

PHP Interview Questions

PHP Interview Questions And Answers

These 135 advanced PHP interview questions and answers were written by PHP experienced professionals to help senior PHP developers. This is one place for all beginners to experienced PHP programmers for basic interview questions to most advanced PHP technical interview questions and answers. Let’s dive into the post and enjoy reading. We hope that this list will help you to crack your next PHP job interview. Happy learning.

PHP Interview Questions And Answers For Freshers

Question # 1) 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.

 

Question # 2) What is PHP and why it is used?

Answer # PHP is a general-purpose scripting language that is especially suited to server-side web development, in which case PHP generally runs on a web server. Any PHP code in a requested file is executed by the PHP runtime, usually to create dynamic web page content or dynamic images used on websites or elsewhere.

 

Question # 3) Why PHP was called as personal home page?

Answer # php is called hypertext pre-processor as its libraries are already compiled. When any person request for any php page in the address bar of the browser that request is first sent to the server then server interpret php files and return back response in form of Html.

 

Question # 4) What is PHP compared to HTML?

Answer # HTML is a language used to describe to a browser how to display text and other objects in a browser window. It is not a programming language. HTML works on a client computer (the system on which the page is being viewed). PHP is a scripting language, and can be used to create web pages written in HTML.

 

Question # 5) What is a PHP 5?

Answer # PHP 5 is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP.

Top PHP Interview Questions

Question # 6) What is PHP and what does it do?

Answer # PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more. There are three main areas where PHP scripts are used. Server-side scripting.

 

Question # 7) What is the difference between PHP and Javascript?

Answer # While JS is used for client side scripting (except in node.js) and PHP is used for server side scripting. Simply, JavaScript codes are executed by your web browser, like the catchy animations or simple calculations . Your browser does all the processing. While PHP runs on the server, where your webpage is stored.

 

Question # 8) What is the difference between HTML and PHP?

Answer # HTML is a language used to describe to a browser how to display text and other objects in a browser window. It is not a programming language. HTML works on a client computer (the system on which the page is being viewed). PHP is a scripting language, and can be used to create web pages written in HTML.

 

Question # 9) What are the advantages of using PHP?

Answer # Advantages of PHP Programming. PHP (Hypertext Pre-Processor) is a server-side web programming language that is widely used for web development. However, here are many languages which are used for web development or web programming. … PHP can run on both UNIX and Windows servers.

 

Question # 10) What is the difference between Python and PHP?

Answer # PHP is a language that’s made for the web. You can make GTK and CLI applications with PHP, but it’s mainly used for websites. Python is used for a lot of stuff like websites, webservers, game frameworks, desktop and CLI application, IDEs and a lot more. There’s also a huge difference in the syntax.

Basic PHP Interview Questions

Question # 11) Why do we use PHP?

Answer # A good benefit of using PHP is that it can interact with many different database languages including MySQL. We work with MySQL at Bluelinemedia since this is also a free language so it makes sense to use PHP. Both PHP and MySQL are compatible with an Apache server which is also free to license.

 

Question # 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.

 

Question # 13) Why is Facebook still using PHP?

Answer # Facebook technology stack consist of application written in many language, including PHP and many others. Facebook still using PHP but it has built a compiler for it so it can be turned into native code on. Facebook doesn’t use PHP for its core system, at Facebook, they uses C++ heavily on back end system.

 

PHP Interview Questions And Answers For 1 Year Experience

 

Question # 14) How does PHP work?

Answer # The PHP software works with the web server, which is the software that delivers web pages to the world. You request a file, the web server happens to be running PHP, and it sends HTML back to the browser, thanks to the programming in PHP.

 

Question # 15) Can you use PHP and Javascript together?

Answer # So, when we develop web pages, we can have a combination of HTML, Javascript, CSS and PHP in our pages. If you need to use a scripting language, such as PHP, once the page has been loaded into the browser, then you must either refresh the page or use Ajax to request more processing at the server side.

 

Question # 16) Why do we use Javascript in PHP?

Answer # PHP is commonly written in-line in the same files as HTML and Javascript, PHP is a server-side language. Javascript is a client-side language. The main difference here is not PHP vs. JavaScript. It’s Client vs. Server. You can’t do server stuff on the client, and you can’t do all the Client stuff on the Server.

 

Question # 17) What is the main difference between asp net and PHP?

Answer # PHP is a programming language whereas ASP.NET is a programming framework. Websites developed by ASP.NET may use C#, but also other languages such as J#. ASP.NET is compiled whereas PHP is interpreted. ASP.NET is designed for windows machines, whereas PHP is platform free (and typically runs on Linux servers).

 

Question # 18) How does session work in PHP?

Answer # the session id is sent to the user when his session is created. it is stored in a cookie (called, by default, PHPSESSID ) that cookie is sent by the browser to the server with each request. the server (PHP) uses that cookie, containing the session_id, to know which file corresponds to that user.

 

Question # 19) How do you end a session in PHP?

Answer # If you want to explicitly end a user’s and delete their data without them having to close their browser, you need to clear the $_SESSION array, then use the session_destroy() function. Session_destroy() removes all session data stored on your hard disk, leaving you with a clean slate.

 

Question # 20) What are the advantages of PHP mysql?

Answer # It is a stable, reliable and powerful solution with advanced features like the following:

  • Data Security
  • On-Demand Scalability
  • High Performance
  • Round-the-clock Uptime
  • Comprehensive Transactional Support
  • Complete Workflow Control
  • Reduced Total Cost of Ownership
  • The Flexibility of Open Source

Core PHP Interview Questions

Question # 21) Is Java is better than PHP?

Answer # PHP and Java are both very similar when it comes to the benefits provided, but they are both very different. PHP is a server side scripting language, while Java is a client side choice. When you use PHP code, you will execute it in the actual server, while Java will be executed on your client’s computer.

 

Question # 22) How do I install PHP?

Answer # Here ie the Manual Installation Procedure

Step 1: download the files. Download the latest PHP 5 ZIP package from www.php.net/downloads.php

Step 2: extract the files

Step 3: configure php.ini

Step 4: add C:php to the path environment variable

Step 5: configure PHP as an Apache module

Step 6: test a PHP file

 

Question # 23) What is the use session in PHP?

Answer # This can be used to persist state information between page requests. Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data. PHP will populate the $_SESSION superglobal with any session data after the session has started.

 

Question # 24) How long does a session last in PHP?

Answer # This is the one. The session will last for 1440 seconds (24 minutes).

 

Question # 25) What is the use of PHP and Mysql?

Answer # PHP is the most popular scripting language for web development. It is free, open source and server-side (the code is executed on the server). MySQL is a Relational Database Management System (RDBMS) that uses Structured Query Language (SQL).

 Latest PHP Interview Questions

Question # 26) Is jquery better than Javascript?

Answer # It may surprise you to learn that JavaScript and jQuery are actually the same thing. In a nutshell, jQuery is a set of JavaScript libraries that have been designed specifically to simplify HTML document traversing, animation, event handling, and Ajax interactions.

 

Question # 27) What is the difference between interpreted and compiled languages?

Answer # Java (interpreted) and C (or C++) (compiled) might have been a better example. Basically, compiled code can be executed directly by the computer’s CPU. The code of interpreted languages however must be translated at run-time from any format to CPU machine instructions. This translation is done by an interpreter.

 

Question # 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.

 

Question # 29) How do I update PHP?

Answer # Changing the PHP Version:

  1. Log  into cPanel.
  2. Click the PHP Configuration button in the Software section.
  3.  Select the version of PHP you want to use from the dropdown.
  4. Click the Update button to save your php configuration.
  5.  Check your changes by viewing your settings in a phpinfo page.

 

Question # 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.

 

Question # 31) What is in PHP 7?

Answer # Designed and refactored for today’s workloads, PHP 7 is the ultimate choice for web developers today. Get started now. Faster performance, less resources, and cool new features like scalar type declarations, the Spaceship Operator, anonymous classes, and more.

 

Question # 32) WHAT IS NULL value in PHP?

Answer # In the PHP world, apparantly uninitialized variables have the Null value, and is set on such a variable returns FALSE.

 

Question # 33) What is a trait in PHP?

Answer # Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

 

Question # 34) What is is_null() in PHP?

Answer # The is_null () function is used to test whether a variable is NULL or not. *Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types. Returns TRUE if var_name is null, FALSE otherwise.

 

Question # 35) What is the difference between null and empty?

Answer # An empty string is a value, but is just empty. Null is special to a database. Null has no bounds, it can be used for string , integer , date , etc. fields in a database. NULL isn’t allocated any memory, the string with NUll value is just a pointer which is pointing to nowhere in memory.

 

PHP Interview Questions And Answers For 2 Year Experience

 

Question # 36) What is a closure in PHP?

Answer # A closure is an object representation of an anonymous function. We can see that the anonymous function in the above code actually returns an object of closure which is assigned to and called using the variable $string. You can say closure is an object oriented way to use anonymous functions.

 

Question # 37) What is final in PHP?

Answer # PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.

 

Question # 38) What is Var_dump?

Answer # The var_dump function displays structured information about variables/expressions including its type and value. Arrays are explored recursively with values indented to show structure. It also shows which array values and object properties are references.

 

Question # 39) What is the difference between null and undefined?

Answer # undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.

 

Question # 40) What is the use of callback in PHP?

Answer # PHP callback are functions that may be called dynamically by PHP. They are used by native functions such as array_map, usort, preg_replace_callback, etc. Here is a reminder of the various ways to create a callback function in PHP, and use it with the native functions.

Advanced PHP Interview Questions

Question # 41) What is a lambda function in PHP?

Answer # To sum up, a lambda function is an anonymous PHP function that can be stored in a variable and passed as an argument to other functions or methods. A closure is a lambda function that is aware of its surrounding context.

 

Question # 42) What is overriding in PHP?

Answer # Overloading is defining functions that have similar signatures, yet have different parameters. Overriding is only pertinent to derived classes, where the parent class has defined a method and the derived class wishes to override that method. In PHP, you can only overload methods using the magic method __call.

 

Question # 43) What is encapsulation in PHP?

Answer # Encapsulation is an OOP (Object Oriented Programming) concept in PHP. Wrapping some data in single unit is called Encapsulation. Second advantage of encapsulation is you can make the class read only or write only by providing setter or getter method. Capsule is best example of Encapsulation.

 

Question # 44) What is boolean in PHP?

Answer # PHP Booleans. A Boolean value is one that is in either of two states. They are known as True or False values, in programming. True is usually given a value of 1, and False is given a value of zero.

 

Question # 45) What is the use of Print_r function in PHP?

Answer # prinf : It is a function which takes atleast one string and format style and returns length of output string. print_r() is used for printing the array in human readable format. they both are language constructs. echo returns void and print returns 1.

 

Question # 46) What is the use of anonymous function in PHP?

Answer # Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses. Anonymous functions are implemented using the Closure class.

 

Question # 47) What is polymorphism in PHP?

Answer # Polymorphism is a long word for a very simple concept. Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface.

 

Question # 48) What is the use of magic function in PHP?

Answer # PHP provides a number of ‘magic’ methods that allow you to do some pretty neat tricks in object oriented programming. These methods, identified by a two underscore prefix (__), function as interceptors that are automatically called when certain conditions are met.

 

Question # 49) What is the use of return in PHP?

Answer # (PHP 4, PHP 5, PHP 7) return returns program control to the calling module. Execution resumes at the expression following the called module’s invocation. If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call.

 

Question # 50) What is the use of die in PHP?

Answer # The die() function prints a message and exits the current script. This function is an alias of the exit() function.

PHP Developer Interview Questions

Question # 51) What is an array in PHP?

Answer # PHP Arrays – An array is a data structure that stores one or more similar type of values in a single value. For example if you want to store 100 numbers then instead of defining 100 variables its easy to define an array of 100 length.

 

Question # 52) How to write comment in php?

Answer # Similiar to the HTML comment, the multi-line PHP comment can be used to comment out large blocks of code or writing multiple line comments. The multiple line PHP comment begins with ” /* ” and ends with ” */ “.

 

Question # 53) What is the difference between $message and $$message in PHP?

Answer # They are both variables. But $message is a variable with a fixed name. $$message is a variable who’s name is stored in $message. For example, if $message contains “var”, $$message is the same as $var.

 

Question # 54) What is the difference between require and include in PHP?

Answer # Require and include functions does the same task i.e. includes and evaluates specified file, but the difference is require will cause a fatal error when the specified file location is invalid or for any error where as include will generate a warning and continue the code execution.

 

PHP Interview Questions And Answers For 3 Year Experience

 

Question # 55) What are the different types of errors in PHP?

Answer # There are four types of errors in PHP.

  1. Warning errors
  2. Notice errors
  3. Fatal errors
  4. Parse errors

Question # 56) PHP Error Constants and their descriptions

Answer #

  1. E_ERROR: A fatal error that causes script termination
  2. E_WARNING: Run-time warning that does not cause script termination
  3. E_PARSE: Compile time parse error
  4. E_NOTICE: Run time notice caused due to error in code
  5. E_CORE_ERROR: Fatal errors that occur during PHP’s initial startup (installation)
  6. E_CORE_WARNING: Warnings that occur during PHP’s initial startup
  7. E_COMPILE_ERROR: Fatal compile-time errors indication problem with script
  8. E_USER_ERROR: User-generated error message
  9. E_USER_WARNING: User-generated warning message
  10. E_USER_NOTICE: User-generated notice message
  11. E_STRICT: Run-time notices
  12. E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
  13. E_ALL: Catches all errors and warnings
  14. E_DEPRECATED
  15. E_USER_DEPRICATED

Question # 57) What is the use of Include_once in PHP?

Answer # The include_once statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include statement, with the only difference being that if the code from a file has already been included, it will not be included again, and include_once returns TRUE .

 

Question # 58) What is Exception Handling in PHP?

Answer # With PHP 5 came a new object oriented way of dealing with errors. Exception handling is used to change the normal flow of the code execution if a specified error (exceptional) condition occurs. This condition is called an exception.

 

Question # 59) Why post method is used in PHP?

Answer # GET can’t be used to send binary data, like images or word documents, to the server. The data sent by GET method can be accessed using QUERY_STRING environment variable. The PHP provides $_GET associative array to access all the sent information using GET method. The POST method transfers information via HTTP headers.

 

Question # 60) What is the use of post in PHP?

Answer # When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named “welcome.php”. The form data is sent with the HTTP POST method. To display the submitted data you could simply echo all the variables.

Senior PHP Developer Interview Questions And Answers

Question # 61) What is the difference between require_once and require in PHP?

Answer # require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example.

 

Question # 62) What is the use of die in PHP?

Answer # The die() function prints a message and exits the current script. This function is an alias of the exit() function.

 

Question # 63) How do you debug PHP?

Answer # To run a debugging session: Start the ide and open the file that contains the source code that you want to debug. Set a breakpoint at each line where you want the debugger to pause. To set a breakpoint, place the cursor at the beginning of a line and press Ctrl-F8/⌘-F8 or choose Debug > Toggle Line Breakpoint.

 

Question # 64) What is the meaning of xdebug?

Answer # Xdebug is a PHP extension which provides debugging and profiling capabilities. It uses the DBGp debugging protocol.

 

Question # 65) What is Chrome logger?

Answer # Chrome Logger is a Google Chrome extension for debugging server side applications in the Chrome console. Most languages include their own logging capabilities, but sometimes it is easier to see your logs right in the browser. Chrome Logger used to be known as ChromePHP.

PHP Developer Interview Questions And Answers For Experienced Candidates

Question # 66) What is the Phpstorm?

Answer # JetBrains PhpStorm is a commercial, cross-platform IDE for PHP built on JetBrains’ IntelliJ IDEA platform. PhpStorm provides an editor for PHP, HTML and JavaScript with on-the-fly code analysis, error prevention and automated refactorings for PHP and JavaScript code.

 

Question # 67) What is Zend Studio for?

Answer # Zend Studio is a commercial, proprietary integrated development environment (IDE) for PHP developed by Zend Technologies, based on the PHP Development Tools (PDT) plugin for the Eclipse platform (the PDT project is led by Zend). … Zend Studio is also integrated with Zend Framework.

 

Question # 68) What is urlencode and urldecode in php?

Answer # urlencode(string) — This PHP function is encodes a string to be used in a query part of a URL. URL encoding is used when placing text in a query string to avoid it being confused with the URL itself. It is normally used when the browser sends form data to a web server.

urldecode(string) – This PHP function id decodes any encoded value in the given string.

 

Question # 69) What is LAMP in PHP?

Answer # LAMP is a combination of Linux, Apache, MySQL and PHP.

 

Question # 70) What is the maximum size of a database in mysql?

Answer #

Operating System            File-size Limit

Win32 w/ FAT/FAT32      2GB/4GB

Win32 w/ NTFS 2TB (possibly larger)

Linux 2.2-Intel 32-bit      2GB (LFS: 4GB)

Linux 2.4+(using ext3 file system) 4TB

Solaris 9/10         16TB

MacOS X w/ HFS+            2TB

NetWare w/NSS file system        8TB

PHP Programming Questions

Question # 71) What is the maximum size of a table in MySQL?

Answer # You are using a MyISAM table and the space required for the table exceeds what is permitted by the internal pointer size. MyISAM permits data and index files to grow up to 256TB by default, but this limit can be changed up to the maximum permissible size of 65,536TB (2567 − 1 bytes).

 

Question # 72) What is the capacity of MySQL database?

Answer # Database Storage Capacity. MySQL is limited by the largest file size that the operating system you run it on can handle (between 4Gb and 256Tb depending on the O/S). With the innoDB table format you can even span multiple files with one table allowing for tables in the database of up to 64Tb.

 

Question # 73) How many records can be stored in MySQL table?

Answer # In InnoDB, with a limit on table size of 64 terabytes and a MySQL row-size limit of 65,535 there can be 1,073,741,824 rows. That would be minimum number of records utilizing maximum row-size limit. However, more records can be added if the row size is smaller.

 

Question # 74) How many columns can be added in a table in mysql?

Answer # MySQL 5.0 Column Count Limits: There is a hard limit of 4096 columns per table, but the effective maximum may be less for a given table. The exact limit depends on several interacting factors. Every table (regardless of storage engine) has a maximum row size of 65,535 bytes.

 

Question # 75) What is varchar mysql?

Answer # Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

 PHP Programming Interview Questions

Question # 76) How big is varchar Max?

Answer # n defines the string length and can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual length of the data entered + 2 bytes. The ISO synonyms for varchar are charvarying or charactervarying.

 

Question # 77) Why triggers are used in mysql?

Answer # The MySQL trigger is a database object that is associated with a table. It will be activated when a defined action is executed for the table. The trigger can be executed when you run one of the following MySQL statements on the table: INSERT, UPDATE and DELETE and it can be invoked before or after the event.

 

Question # 78) How big is Nvarchar Max?

Answer # In Nvarchar “n” defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying.

 

Question # 79) Why delimiter is used in mysql?

Answer # By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server. To redefine the mysql delimiter, use the delimiter command.

 

Question # 80) What is a stored procedure in mysql?

Answer # A procedure (often called a stored procedure) is a subroutine like a subprogram in a regular computing language, stored in database. A procedure has a name, a parameter list, and SQL statement(s). All most all relational database system supports stored procedure, MySQL 5 introduce stored procedure.

PHP Technical Interview Questions

Question # 81) What does a delimiter do in mysql?

Answer # delimiter is the marker for the end of each command you send to the mysql command line client. delimiter is not only related to triggers, but defining triggers and stored procedures is one strong use case as you wish them to contain semicolons (;) which are otherwise the default delimiter.

 

Question # 82) What is a definer in mysql?

Answer # All stored programs (procedures, functions, triggers, and events) and views can have a DEFINER attribute that names a MySQL account. If the DEFINER attribute is omitted from a stored program or view definition, the default account is the user who creates the object.

 

Question # 83) When should you use a stored procedure?

Answer # The benefits of using stored procedures in SQL Server rather than application code stored locally on client computers include: They allow modular programming. They allow faster execution. They can reduce network traffic.

 

Question # 84) What is the use of limit in mysql?

Answer # Limit Data Selections From a MySQL Database. MySQL provides a LIMIT clause that is used to specify the number of records to return. The LIMIT clause makes it easy to code multi page results or pagination with SQL, and is very useful on large tables. Returning a large number of records can impact on performance.

 

Question # 85) What is the use of dual table in mysql?

Answer # The DUAL table is a special one-row, one-column table present by default in Oracle and other database installations. In Oracle, the table has a single VARCHAR2(1) column called DUMMY that has a value of ‘X’. It is suitable for use in selecting a pseudo column such as SYSDATE or USER.

Advanced PHP Interview Questions

Question # 86) What is the use of inner join in mysql?

Answer # The MySQL INNER JOIN clause matches rows in one table with rows in other tables and allows you to query rows that contain columns from both tables. The INNER JOIN clause is an optional part of the SELECT statement.

 

Question # 87) What is the difference between an inner and outer join?

Answer # An inner join will only select records where the joined keys are in both specified tables. A left outer join will select all records from the first table, and any records in the second table that match the joined keys.

 

Question # 88) What is the use of offset in mysql?

Answer # Both MySQL and PostgreSQL support a really cool feature called OFFSET that is usually used with a LIMIT clause. The LIMIT clause is used to limit the number of results returned in a SQL statement.

PHP Interview Questions And Answers For 4 Year Experience

Question # 89) What is stdClass in PHP?

Answer # stdClass is a PHP generic empty class and stdClass is used to create the new Object.  stdClass is a kind of Object in Java or object in Python but not actually used as universal base class.

 

Question # 90) What are soundex() and metaphone() functions in PHP?

Answer # soundex and metaphone can be used to find strings that sound similar when pronounced out loud.

soundex() function calculates the soundex key of a string. A soundex key is a four character long alphanumeric strings that represents English pronunciation of a word.

metaphone() the metaphone() function calculates the metaphone key of a string. A metaphone key represents how a string sounds if pronounced by an English person.

 

Question # 91) How to parse configuration file in PHP?

Answer # The parse_ini_file() function parses a configuration (ini) file and returns the settings.

 

Question # 92) What is PSR in PHP?

Answer # The PHP Standard Recommendation (PSR) is a PHP specification published by the PHP Framework Interop Group. Similar to Java Specification Request for Java, it serves the standardization of programming concepts in PHP.

PHP Logical Interview Questions And Answers

Question # 93) What is Trait in PHP?

Answer # Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

 

Question # 94) What is the difference between php traits vs interfaces?

Answer # The main difference is that, with interfaces, you must define the actual implementation of each method within each class that implements said interface, so you can have many classes implement the same interface but with different behavior, while traits are just chunks of code injected in a class.

 

Question # 95) Can you give example for Trait in PHP?

Answer #

<?php

trait ezcReflectionReturnInfo {

function getReturnType() { /*1*/ }

function getReturnDescription() { /*2*/ }

}

class ezcReflectionMethod extends ReflectionMethod {

use ezcReflectionReturnInfo;

/* … */

}

class ezcReflectionFunction extends ReflectionFunction {

use ezcReflectionReturnInfo;

/* … */

}

?>

 

Question # 96) How to get IP address of a server in PHP?

Answer # Try $_SERVER[‘SERVER_ADDR’] . It will be the IP address that the server is listening on. You can use DNS functions (e.g., gethostbyaddr() ) to get the host name.

 

Question # 97) Is there an easy way to delete an element from a PHP array?

Answer # If we want to delete just one array element you can use unset() method or alternative array_splice() method. Also if you have the value and don’t know the key to delete the element you can use array_search() method to get the key.

PHP Interview Questions And Answers For Experienced

Question # 98) Can you explain, when to use If-else if-else over switch statements?

Answer # If there is switching on the value of a single variable then switch is recommended every time. Otherwise, stick with multiple if-else statements.

 

Question # 99)  When do you use define() and when do you use const. What are the main differences between those two?

Answer # PHP 5.3 there are two ways to define constants: Either using the const keyword or using the  define() function:

const FOO = ‘BAR’;

define(‘FOO’, ‘BAR’);

The fundamental difference between those two ways is that const defines constants at compile time, whereas define() defines them at runtime. As const are language constructs and defined at compile time they are a bit faster than define().

PHP Interview Questions And Answers For 5 Year Experience

 

Question # 100) What is self in PHP?

Answer # In PHP self keyword is used to access static properties and methods.

 

Question # 101) What is $this?

Answer # It is the way to reference an instance of a class from within itself, the same as many other object-oriented languages.  $this refers to the class you are in. In PHP, the pseudo-variable $this is available when a method is called from within an object context.

 

Question # 102) When to use self over $this?

Answer # Use $this to refer to the current object. Use self to refer to the current class.

 

Question # 103) What is the difference between Apache and Tomcat?

Answer # Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat. So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.

 

Question # 104) What is Nginx and what is it used for?

Answer # NGINX (Pronounced as Engine-X) is an open source, lightweight, high-performance web server or proxy server. Nginx used as reverse proxy server for HTTP, HTTPS, SMTP, IMAP, POP3 protocols, on the other hand, it is also used for servers load balancing and HTTP Cache.

 

Question # 105) Which is the best Web server?

Answer # There are different web servers available for different technologies.

LAMP: Linux, Apache, MySQL and PHP.

WIMP: Windows, IIS, MySQL/MS SQL Server and PHP.

WAMP: Windows, Apache, MySQL/MS SQL Server and PHP.

LEMP: Linux, NGINX, MySQL and PHP.

PHP Interview Questions And Answers For Experienced Candidates

Question # 106) What is the difference between Apache vs NIGINX?

Answer # The Apache HTTP server and NGINX are the two most popular open source web servers in the world today. The Apache web servers have been in use since 1995. Apache powers more websites than any other product. Because the open-source Apache web server has been available for so many years, and has so many users, lots of modules have been written to expand its functionality.

But Apache slows down under heavy load, because of the need to spawn new processes, thus consuming more computer memory. It also creates new threads that must compete with others for access to memory and CPU. Apache will also refuse new connections when traffic reaches the limit of processes configured by the administrator.

Nginx is an open source web server written to address some of the performance and scalability issues associated with Apache. The product is open source and free, but Nginx offers support if you buy its Nginx Plus version. Nginx is indeed event-based. They call their architecture “event-driven and asynchronous”. Apache relies on processes and threads.

 

Question # 107) What is .htaccess in PHP?

Answer # .htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn ‘loaded via the Apache Web Server’, then the .htaccess file is detected and executed by the Apache Web Server software.

 

Question # 108) What are advantages of .htaccess?

Answer # There are many advantages using .htaccess file in PHP:

  • URL redirecting
  • Managing error pages
  • Password Protection
  • Visitor blocking facilities by IP address
  • Setting Config variable and Environment variable

 

Question # 109) How to redirect a URL from http to https in .htaccess?

Answer # Using this below code, we can redirect a URL from http to https

RewriteEngine on

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

 

Question # 110) How to redirect https to http URL and vice versa in .htaccess?

Answer # Using this below code, we can redirect a URL from http to https

Redirect https to http

RewriteEngine On

RewriteCond %{HTTPS} on

RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Real Time PHP Interview Questions And Answers

Question # 111) What is a composer in PHP?

Answer # Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries.

 

Question # 112) What is PHP artisan?

Answer # Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.

 

Question # 113) What is the difference between == and === in PHP?

Answers # The difference between the loosely == equal operator and the strict === identical operator is:

$a ==  $b │ Equal     │ TRUE if $a is equal to $b after type juggling.

$a === $b │ Identical │ TRUE if $a is equal to $b, and they are of the same type.

 

Question # 114) What is the output of the following PHP code?

Answers: $i = 012;

echo $i / 2;

Explanation: You might think that output for the above code is 6 right. That’s the wrong answer. But the correct output should be 5. The zero indicates at the beginning of a number as an octal number in PHP, so the number 012 evaluates to the decimal number 10 instead to decimal 12. Then the output should be 5.

MySQL Interview Questions And Answers For Experienced

Question # 115) What is SQL injection?

Answers # SQL injection (or a SQL injection attack) occurs when a user provides SQL code as user input for a Web page, and the SQL code is then executed in the database.

 

Question # 116) Why does SQL injection happen?

Answers # SQL injection is an attack technique that exploits a security vulnerability occurring in the database layer of an application . Hackers use injections to obtain unauthorized access to the underlying data, structure, and DBMS. It is one of the most common web application vulnerabilities.

 

Question # 117) What is Mysql_real_escape_string used for?

Answers # In the case of MySQL this means: mysql_real_escape_string() calls MySQL’s library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ‘, ” and \x1a.

 

Question # 118) What is input sanitization in PHP?

Answers # PHP filters are used to validate and sanitize external input. The PHP filter extension has many of the functions needed for checking user input, and is designed to make data validation easier and quicker.

 

Question # 119) What is the use of Stripslashes in PHP?

Answers # Definition and Usage. The stripslashes() function removes backslashes added by the addslashes() function. This function can be used to clean up data retrieved from a database or from an HTML form.

 

Question # 120) What is the use of Htmlspecialchars in PHP?

Answers # In many PHP legacy products the function htmlspecialchars($string) is used to convert characters like < and > and quotes a.s.o to HTML-entities.

 

Question # 121) What is the use of Addslashes in PHP?

Answers # Description. string addslashes ( string $str ) Returns a string with backslashes before characters that need to be escaped. These characters are single quote (‘), double quote (“), backslash (\) and NUL (the NULL byte).

 

Question # 122) What is XSS in PHP?

Answers # Cross-Site Scripting (abbreviated as XSS) is a class of security vulnerability whereby an attacker manages to use a website to deliver a potentially malicious JavaScript payload to an end user. XSS vulnerabilities are very common in web applications.

 

Question # 123) What is the use of isset in PHP?

Answers # isset() function. The isset () function is used to check whether a variable is set or not. If a variable is already unset with unset() function, it will no longer be set. The isset() function return false if testing variable contains a NULL value.

Real Time PHP Interview Questions And Answers

Question # 124) What is URL encoding and decoding in PHP?

Answers # urlencode(string)  This PHP function encodes a string to be used in a query part of a URL. urldecode(string) — This PHP function is decodes the query part of a URL string. URL encoding is used when placing text in a query string to avoid it being confused with the URL itself.

 

Question # 125) What is the use of trim in PHP?

Answers # The trim() function removes whitespace and other predefined characters from both sides of a string.

Related functions: ltrim() – Removes whitespace or other predefined characters from the left side of a string.

rtrim() – Removes whitespace or other predefined characters from the right side of a string.

 

Question # 126) What is the mysql injection?

Answers # MySQL injection refers to the act of someone inserting a MySQL statement to be run on your database without your knowledge. Injection usually occurs when you ask a user for input, like their name, and instead of a name they give you a MySQL statement that you will unknowingly run on your database.

 

Question # 127) What is the use of die in PHP?

Answers # The die() function prints a message and exits the current script. This function is an alias of the exit() function.

 

Question # 128) What does explode do in PHP?

Answers # You can also convert between strings and arrays by using the PHP implode and explode functions: implode implodes an array to a string, and explode explodes a string into an array.

 

Question # 129) What are the delimiters in PHP?

Answers # When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character. Often used delimiters are forward slashes (/), hash signs (#) and tildes (~).

 

Question # 130) Why Print_r is used in PHP?

Answers # print_r() is used for printing the array in human-readable format.

Scenario-Based PHP Interview Questions And Answers

Question # 131) What is Var_dump?

Answers # The var_dump function displays structured information about variables/expressions including its type and value.

 

Question # 132) What are the new features available in PHP 7?

Answers # New features from PHP 7 are:

  • Scalar type declarations – Scalar type declarations come in two flavors. One is coercive and the other one is strict.
  • Return type declarations
  • Null coalescing operator
  • Spaceship operator
  • Constant arrays using define()
  • Anonymous classes
  • Unicode codepoint escape syntax
  • Closure::call()

Question # 133) How do you define a constant in PHP?

Answers # A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name).

 

Question # 134) What is Warning – “Cannot modify header information – headers already sent”?

Answers # In PHP when you output something (do an echo or print) if has to send the HTTP headers at that time. If you turn on output buffering you can output in the script but PHP doesn’t have to send the headers until the buffer is flushed. This will turn output buffering out without the need to call ob_start().

Accenture PHP Interview Questions And Answers

Question # 135) Explain about getters and setters in PHP?

Answers # “Getters” and “Setters” are object methods that allow you to control access to a certain class variables / properties. Sometimes, these functions are referred to as “mutator methods”. A “getter” allows to you to retrieve or “get” a given property. A “setter” allows you to “set” the value of a given property.

 

Question # 136) What are majic methords in PHP?

Answers # PHP provides a number of ‘magic’ methods that allow you to do some pretty neat tricks in object oriented programming. These methods, identified by a two underscore prefix (__), function as interceptors that are automatically called when certain conditions are met.

Give me some examples of majix methods?

__construct()

The __construct() method is by far the most commonly used magic method. This is where you do any initialization you need when an object is created.

__destruct()

The __destruct() method is called when the object is destroyed. It accepts no arguments and is commonly used to perform any cleanup operations such as closing a database connection.

__get()

The __get() method is called when code attempts to access a property that is not accessible. It accepts one argument, which is the name of the property. It should return a value, which will be treated as the value of the property.

__set()

The __set() method is called when code attempts to change the value a property that is not accessible. It accepts two arguments, which are the name of the property and the value.

__isset()

The __isset() method is called when code calls isset() on a property that is not accessible. It accepts one argument, which is the name of the property. It should return a Boolean value representing the existence of a value.

__unset()

The __unset() method is called when code attempts to unset() a property that is not accessible. It accepts one argument, which is the name of the property.

__toString()

The __toString() method is called when code attempts to treat an object like a string. It accepts no arguments and should return a string.

__set_state()

The static __set_state() method is called when the var_export() function is called on our object.

__clone()

The __clone() method can be used to solve this problem. It is called on the copy of a cloned object after cloning takes place.

__sleep()

The __sleep() method is called when the serialize() function is called on the object. It accepts no arguments and should return an array of all properties that should be serialized.

__wakeup()

The __wakeup() method is called when the unserialize() function is called on the stored object. It accepts no arguments and does not need to return anything. Use it to reestablish any database connection.

__call()

The __call() is called when code attempts to call inaccessible or nonexistent methods. It accepts two arguments: the name of the called method and an array of arguments.

__callStatic()

The __callStatic() (available as of PHP version 5.3) is identical to __call() except that it is called when code attempts to call inaccessible or nonexistent methods in a static context.

__invoke()

The __invoke() is called when code tries to use the object as a function. Any arguments defined in this method will be used as the function arguments.

__autoload()

This is not a magic method, but it is still very useful. The __autoload() function is automatically called when a class that doesn’t exist is referenced.

Coding compiler hope that these 136 PHP interview questions and answers for freshers and 1 2 3 4 5 years experienced professionals will help you to crack your next PHP job interview. If you know any other PHP technical interview questions, please write in below comment box, these PHP questions will be helpful for fellow PHP professionals.

RELATED INTERVIEW QUESTIONS

  1. Kubernetes Interview Questions
  2. Docker Interview Questions
  3. CEH Interview Questions
  4. CyberArk Interview Questions
  5. Appian Interview Questions
  6. Drools Interview Questions
  7. Talend Interview Questions
  8. Selenium Interview Questions
  9. Ab Initio Interview Questions
  10. AB Testing Interview Questions
  11. Mobile Application Testing Interview Questions
  12. Pega Interview Questions
  13. UI Developer Interview Questions
  14. Tableau Interview Questions
  15. SAP ABAP Interview Questions
  16. Reactjs Interview Questions
  17. UiPath Interview Questions
  18. Automation Anywhere Interview Questions
  19. RPA Interview Questions
  20. RPA Blue Prism Interview Questions
  21. Ranorex Interview Questions
  22. AWS Interview Questions
  23. SSRS Interview Questions
  24. SQL Interview Questions
  25. Informatica MDM Interview Questions
  26. CyberArk Interview Questions
  27. SAP SD Interview Questions
  28. SAP EWM Interview Questions
  29. Advanced Javascript Interview Questions
  30. Angular 2 Interview Questions

Leave a Reply

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