PHP is an important part of the web world, and every web developer should have the basic knowledge of PHP. Here are the Most Important PHP Interview Questions, which should help you become a best PHP coder. We hope you find these questions useful.
1.What is .htaccess in PHP?
.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
2.What is the importance of “action” attribute in an HTML form?
The action attribute determines where to send the form-data in the form submission.
3.What is the use of isset in PHP?
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.
4.Why post method is used in PHP?
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.
5.Can you explain, when to use If-else if-else over switch statements?
If there is switching on the value of a single variable then switch is recommended every time. Otherwise, stick with multiple if-else statements.
6.What are the different types of errors in PHP?
There are four types of errors in PHP.
- Warning errors
- Notice errors
- Fatal errors
- Parse errors
7.What is the use of die in PHP?
The die() function prints a message and exits the current script. This function is an alias of the exit() function.
8.What is the capacity of MySQL database?
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.
9.How to get IP address of a server in PHP?
$_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.
10.What is SQL injection?
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.
11.Why does SQL injection happen?
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.
12.How long does a session last in PHP?
The session will last for 24 minutes (1440 seconds).
13.What is the difference between interpreted and compiled languages?
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.
14.What is the difference between null and empty?
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.
15.What is the use of a magic function in PHP?
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.
16.What is the difference between require and include in PHP?
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.
17.What is the difference between $message and $$message in PHP?
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.
18.How does session work in PHP?
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.
19.What is the difference between Python and PHP?
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, web servers, game frameworks, desktop and CLI application, IDEs and a lot more. There’s also a huge difference in the syntax.
20.What are the new features available in PHP 7?
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