1. Differentiate between static and dynamic websites.
Static Website
The content cannot be modified after the script is executed The content can be changed even at the runtime
Dynamic Website
No ability to change the content as it is predefined The content can be changed easily by manipulation and reloading
2. What is PHP primarily used for?
PHP has a variety of uses for developers. Following are some of the most often utilized notions that PHP offers:
With PHP, it becomes quite easy to grant restricted access to the needed material of the website.
It allows users to access individual cookies and set them as per requirement.
Database manipulation actions, such as addition, deletion, and update, can be done quickly.
Form handling, including capabilities that entail file handling concepts and email integration, is utilized widely.
The system module allows users to conduct a range of system functions such as open, read, write, etc.
3. Is PHP a case-sensitive scripting language?
The answer to this is both yes and no. Variables and their declaration in PHP are totally case sensitive but function names are not.
For example, user-defined functions in PHP can be defined in uppercase but afterwards referred to in lowercase, and it would still function appropriately.
4. What is the meaning of PEAR in PHP?
PEAR stands for PHP Extension and Application Repository. It is one of the frameworks and acting repositories that host all of the reusable PHP components. Alongside providing some of the PHP libraries, it also provides you with a simple interface to automatically install packages.
5. How is a PHP script executed?
PHP scripts may be readily executed using the command-line interface (CLI) (CLI). The syntax is as follows:
php filename.php
Here, filename refers to the file that includes scripts. The extension .php is needed alongside the filename.
6. What are the sorts of variables present in PHP?
There are eight primary data types in PHP as illustrated below:
- Array: A named and ordered collection of data
- Boolean: A logical value (True or False) (True or False)
- Double: Floating point figures such as 5.1525
- Integer: Whole numbers without a floating point
- Object: An instance of classes, having data and functions
- NULL: A specific data type, providing just the NULL data
- Resource: Special variables that carry references to external resources
- String: A sequence of characters such as, “Hello learners!\”
7. What are the variable-naming conventions you should follow in PHP?
There are two basic principles that you have to follow when naming a variable in PHP. They are as follows:
Variables can only begin with letters or underscores.
Special characters such as +, %, -, &, etc. cannot be used.
8. What are the major properties of a PHP variable?
Following are some of the most essential features of the usage of variables in PHP:
Variables can be declared before the value assignment.
A variable value assignment happens via the ‘=’ operator.
Every variable in PHP is indicated with a $ (dollar) sign.
The value of a variable depends on its latest assigned value.
PHP variables are not intrinsic. There is no specific declaration.
Next up on these PHP interview questions for freshers, you need to comprehend what NULL is.
9. What is NULL in PHP?
NULL is a special data type in PHP used to denote the presence of only one value, NULL. You cannot assign any other value to it.
NULL is not case sensitive in PHP and can be declared in two ways as shown below:
$var = NULL:
Or
$var = null;
Both of the above syntaxes work properly with PHP.
10. How are constants defined in PHP?
Constants can be defined easily in PHP by making use of the define() method. This function is used to define and get out the values of the constants quickly.
Constants, as the name suggests, cannot be modified after definition. They do not require the PHP syntax of starting with the customary $ sign.
11. What is the use of the constant() function in PHP?
The constant() function is used to retrieve the values predefined in a constant variable. It is utilized notably when you do not know the name of the variable.
12. What are the various constants predefined in PHP?
PHP comprises of several constants, and following are some of the widely used ones:
_METHOD_: Represents the class name
_CLASS_: Returns the class name
_FUNCTION_: Denotes the function name
_LINE_: Denotes the working line number
_FILE_: Represents the path and the file name
13. Differentiate between variables and constants in PHP.
Variable
Variables can have modified routes Constants cannot be changed
The $ assignment is used for definition Constants are defined using the define() method
Constant
The default scope is the current access scope Constants can be accessed throughout without any scoping rules
Compulsory usage of the $ sign at the start No need for the $ sign for constants
14. What does the phrase ‘PHP escape’ mean?
PHP escape is a method that is used to tell the PHP parser that certain code parts are different from PHP code. This gives the basic means to separate a section of PHP code from the other components of the application.
15. Differentiate between PHP4 and PHP5.
PHP4
No support for static methods
Abstract classes cannot be stated
The mechanism of call-by-value is employed
Constructors can have class names
PHP5
Allows the employment of static methods
Abstract classes can be specified
The method of call-by-reference is employed
Constructors have separate names
16. How are two objects compared in PHP?
PHP gives you with the ‘==’ operator, which is used to compare two objects at a time. This is used to examine if there is a common existence of characteristics and values between the objects in comparison.
The ‘===’ operator is also used to compare if two objects under consideration are reference to the same class.
Next up on these PHP interview questions, you need to understand a key notion.
17. What is the meaning of break and continue statements in PHP?
Break: This statement is used in a looping construct to terminate the execution of the iteration and to immediately execute the next snippet of code outside the block of the looping construct.
Continue: This statement is used to skip the current iteration of the loop and continue to execute the next iteration until the looping construct is exited.
18. What are some of the prominent frameworks in PHP?
There are numerous frameworks in PHP that are notable for their usage. Following are some of them:
CodeIgniter
CakePHP
Laravel
Zend
Phalcon
Yii 2
19. What is the use of the final class and the final method in PHP?
The ‘final’ keyword, if included in a declaration, implies that the current method does not permit overriding by other classes. This is used when there is a requirement to construct an immutable class.
Note: Properties cannot be defined as final. It is only methods and classes that get to be final.
Next up on this core PHP interview questions and answers blog, let us take a look at the intermediate questions.
20. How does JavaScript interact with PHP?
JavaScript is a client-side programming language, while PHP is a server-side scripting language. PHP has the ability to produce JavaScript variables, and this may be run easily in the browser, so making it easy to send variables to PHP using a simple URL.
21. Does PHP interact with HTML?
Yes, HTML and PHP interaction is the basis of what makes PHP what it is. PHP scripts have the ability to generate HTML mode and transfer around information extremely easily.
PHP is a server-side scripting language, while HTML is a client-side language. This contact helps bridge the gaps and employ the best of both languages.
22. What are the types of arrays supported by PHP?
There are three basic types of arrays that are utilized in PHP.
Indexed arrays: These are arrays that include numerical data. Data access and storage are linear.
Associative arrays: There are arrays that contain strings for indexing elements.
Multidimensional arrays: These are arrays that contain more than one index and dimension.
23. How does the ‘foreach’ loop operate in PHP?
The foreach statement is a looping construct used in PHP to cycle and loop through the array data type. The working of foreach is simple; with every single pass of the value, elements get assigned a value and pointers are incremented. This operation is repeated till the end of the array.
The following is the syntax for using the foreach command in PHP:
foreach(array)
{
Code inside the loop;
}
24. Differentiate between require() and require once() routines.
require()
The inclusion and evaluation of files Includes files if they are not included before
require once()
Preferred for files with fewer functionalities Preferred when there are a lot of functions
25. What are the data types present in PHP?
PHP offers three forms of data management, and they are as shown in the following table:
Scalar Data Types
boolean
Integer<>
Float
String
Compound Data Types
Array
Object
Special Data Types
NULL
Resource
26. How can a text be printed using PHP?
A text can be output onto the working environment utilizing the following methods:
Echo
Print
The following code denotes the usage of both:
<?
php echo \”Using echo\”;
print \”Using print\”; ?
>
27. Is it feasible to set indefinite execution time in PHP?
Yes, it is feasible to have an indefinite execution period in PHP for a script by adding the set time limit(0) function to the beginning of a script.
This can also be executed in the php.ini file if not at the beginning of the script.
28. What is the use of constructors and destructors in PHP?
Constructors are utilized in PHP as they allow you to pass arguments when constructing a new object quickly. This is used to initialize the variables for the particular object in consideration.
Destructors are methods used to destroy an item. Both of these are unique methods offered in PHP enable you to conduct complex processes utilizing a single step.
29. What are some of the top Content Management Systems (CMS) utilized in PHP?
There are several CMS that are utilized in PHP. The popular ones are as indicated below:
WordPress
Joomla
Magneto
Drupal
30. How are comments used in PHP?
There are two ways to use comments in PHP. They are single-line comments and multi-line comments.
Single-line comments can be utilized using the standard ‘#’ sign.
Example:
<?
php
# This is a comment
echo \”Single-line comment\”;
?
>Multi-line comments can be denoted with ‘/* */’ in PHP.
Example:
<?
php
/*
This is
a
Multi-line
Comment
In PHP;
*/
echo \”Multi-line comment\”;
?>
Next up on these essential PHP interview questions, you need to know the difference between an indexed and an associative array. Read on.
31. What is the most popular method for hashing passwords in PHP?
The crypt() method is often utilized for this capability as it gives a big quantity of hashing algorithms that can be used. These algorithms include md5, sha1 or sha256.
32. Differentiate between an indexed array and an associative array.
Indexed arrays have elements that have a numerical index value.
Example: $color=array(\”red\”,\”green\”,\”blue\”);
Here, red is at index 0, green at 1, and blue at 2.
Associative arrays, on the other hand, hold elements with string indices as seen below:
Example: $salary=array(\”Jacob\”=>\”20000\”,\”John\”=>\”44000\”,\”Josh\”=>\”60000\”);
33. What is the difference between ASP.NET and PHP?
ASP.NET
- A programming framework
- Compiled and executed
- Designed for use on Windows
PHP
- A scripting language
- Interpreted mode of execution
- Platform independent
34. What are sessions and cookies in PHP?
Sessions are global variables that are saved on the server in the architecture. Every single session is tagged with a unique server ID that is later used to interact with the storage and retrieval of values.
Cookies are entities used to identify distinct users in the architecture. It is a tiny file that the server plants into the client system. This is done to acquire important information from the client for the development of various parts of the server.
35. Is typecasting supported in PHP?
Yes, typecasting is provided by PHP and can be done very easy. Following are the types that can be cast in PHP:
(int), (integer): Cast to integer
(bool), (boolean): Cast to boolean
(float), (double), (real): Cast to float
(string): Cast to string
(array): Cast to array
(object): Cast to object
36. Can a form be submitted in PHP without making use of a submit button?
Yes, a form can be submitted without the explicit usage of a button. This is done by making use of the JavaScript submit() method easily.
Next up on this PHP developer interview questions, it is necessary that you know about PHP in detail. Read on.
37. Does PHP support variable length argument functions?
Yes, PHP supports the usage of variable length argument functions. This basically means that you can send any amount of parameters to a function. The syntax just entails using three dots before the argument name as demonstrated in the following example:
<?
php
function add(…$x) {
$sum = 0;
foreach ($x as $n) {
$sum += $n;
}
return $sum;
}
echo add(5, 6, 7, 8,9);
?
>
Output: 35
38. What is the use of session start() and session destroy() functions?
In PHP, the session start() function is used to start a new session. However, it can also restart an existing session if it is halted. In this situation, the return will be the current session if resumed.
Syntax:
session start();
The session destroy() function is generally used to destruct all of the session variables as seen below:
<?
php
session start();
session destroy();
?>
39. How do you open a file in PHP?
PHP supports file operations by giving users with a multitude of file-related functions.
In the event of opening a file, the fopen() method is used. This function can open a file or a URL as per demand. It takes two arguments: $filename and $mode.
Syntax:
resource fopen ( string $filename , string $mode [, bool $use include path = false [, resource $context ]] )
40. What are the different forms of PHP errors?
There are three primary sorts of errors in PHP. They are as follows:
Notice: A notice is a non-critical error that is not displayed to the user.
Warning: A warning is an error that is displayed to the user while the script is running.
Fatal error: This is the most critical form of error. A fatal error will prompt immediate termination of the script.
41. How can you retrieve the IP address of a client in PHP?
The IP address of a client, who is connected, can be acquired easily in PHP by making use of the following syntax:
$_SERVER[\”REMOTE ADDR\”];
42. What is the use of $message and $$message in PHP?
Both $message and $$message are variables in PHP. The difference lies in the name. While $message is a variable with a defined name, $$message is a variable with a name that is really stored in $message.
Consider the following example:
If $message consists of ‘var’, then $$message is nothing but ‘$var’.
43. Differentiate between GET and POST methods in PHP.
Methods: GET and POST
GET
There is no limit on the size of the data, but the GET method can only send up to 1024 characters at once.
The data that is sent via the HTTP protocol and the header is accessed using the environment variable QUERY STRING.
POST
POST enables binary data in addition to ASCII, although GET does not.
Here, the provided information is accessed via the $_POST associative array rather than the $_GET associative array.
44. What purpose do PHP lambda functions serve?
The lambda function, which is anonymous, is used to first store data in a variable before passing it as arguments to other procedures or functions.
Think about the following instance:
array(4, 5, 10); $input
$input, function ($x), return $x > 4, $output = array filter($input, $x);
Here\’s how a lambda function is defined:
function ($x) return $x greater than four ; );
This is then used to put data into a variable so you may access it as needed without having to define it again.
45. Explain the differences between runtime exceptions and compile-time exceptions in PHP.
Compile-time exceptions are what they sound like: they happen when a script is being built, during the compilation process. A nice illustration of a compile-time exception is the FileNotFoundException.
A runtime exception is one that prevents the script from continuing to execute. An illustration of a runtime exception is the ArrayIndexOutOfBoundException.
46. What does type hinting in PHP mean?
While it is necessary to explicitly define the data type of an argument when passing it through a function, PHP uses type hinting.
PHP will perform a short analysis to see whether all the required data types are present when this function is first invoked. If it\’s different, the runtime will halt and throw an error.
The following of these fundamental PHP interview questions requires you to comprehend how to link PHP to a URL.
47. How does PHP connect to a URL?
PHP may be simply connected to any URL by using the cURL library. With the normal PHP installation, this library is included.
Client-side URL, or \”cURL,\” is a technology that enables users to access a URL and retrieve data from that page for display.
48. What are the procedures for building a new MySQL and PHP database?
To establish a new MySQL database in PHP, there are four fundamental stages. These are what they are:
The PHP script first establishes a connection to the MySQL server.
The connection is verified a second time. If the connection works, you can create a test query to make sure.
The database\’s creation queries are entered and then saved in a string variable.
The prepared queries are then carried out one by one.
49. How does PHP handle string concatenation?
The dot(.) operator in PHP makes string concatenation simple. Think about the following instance:
<?
echo $string1; php $string1=\”Welcome\”; $string2=\”to coderazaa\” \” \” . ; $string2 >
Welcome to coderazaa, output
50. Do you own any credentials that will strengthen your application for the position of PHP Developer?
The purpose of this inquiry is to determine whether you have any exposure to ongoing projects and practical experience. This is typically offered by a reputable certification school, and it conveys to the interviewer that you are committed to the career path you are pursuing. If you have any experience that is relevant, be sure to include what you learnt and used during the certification course.
51. PHP and Java are compared.
PHP
Area of deployment: Server-side scripting
Type of language: Dynamically typed
No, offering a wide range of APIs
Java
Programming for general-purpose deployment
Type of language: Statically typed
Yes, offering a wide variety of APIs
52. How can we use PHP to encrypt a password?
One-way encryption is made using the crypt () function. There is one required parameter and one optional parameter. The definition of the function is
(input string, salt) crypt
where salt is an optional parameter and input string is the string that needs to be encrypted. PHP uses DES as an encryption method.
53. Without a submit button, describe how to submit a form.
Without the button, a form can be posted or submitted in the following ways:
A JavaScript function can be called to submit the form on the OnClick event of a label in the form.
Example:
document.form name.submit()
Using a Hyperlink: A JavaScript function can be called when the link is clicked.
Example:
A5 PHP IQA code
In addition to using the submit button, the following methods are also available for submitting forms:
clicking a link to submit a form
choosing a choice from a drop-down box and submitting the form while triggering a onChange event
JavaScript usage
document.form.submit();
Making use of header(\”location:page.php\”);
54. How can we speed up the PHP script\’s execution?
The php.ini file specifies that a PHP script may run for a maximum of 30 seconds by default. It uses the set time limit function (int sec). It takes an infinite amount of time if the value passed is \”0.\” It should be noted that the script will run for 45 seconds if the default timer is set to 30 seconds and a 20-second limit is specified in set time limit().
You can extend this time by changing max execution time in seconds. The time needs to be changed while still respecting the server\’s environment. This is due to the fact that altering the execution time will have an impact on every website the server hosts.
You can lengthen the script\’s execution time by:
Using the PHP script\’s sleep() function
By means of the set time limit() function
The time frame is 30 seconds by default. To impose no time limit, the time limit can be set to zero.
55. Describe Zend Engine.
PHP utilizes Zend Engine internally as a compiler and runtime engine. Zend OPCodes are created by compiling PHP scripts into memory.
Following the execution of these OPCodes, the client receives the HTML that was produced.
The Zend Engine manages resources, memory, and other standard services for the PHP programming language. The performance, dependability, and extensibility of PHP have contributed significantly to its rising popularity.
56. What library does PHP use for PDF?
Using PDFlib version 6, the PDF functions in PHP can produce PDF files. In addition to the function-oriented API for PHP4, PDFlib also provides an object-oriented API for PHP5.
The Panda module is another option.
FPDF is a PHP class that enables the creation of PDF files using only PHP (without using PDFlib). The F in FPDF stands for Free; we are free to use it for any purpose and alter it as necessary. With the exception of zlib to enable compression and GD to support GIF, FPDF works with both PHP4 and PHP5.
57. What brand-new features does PHP7 offer?
Performance enhancements for Zend Engine 3 and support for 64-bit integers on Windows
standardized variable syntax
AST-based process for compilation
Call Added Closure ()
Consistency of bitwise shift across platforms
Coalesce (Null) operator
Unicode escape code syntax
Return type statements
declarations of scalar types (integer, float, string, and boolean)
58. Describe htaccess. Where and why do we use it?
The Apache Server\’s.htaccess configuration files offer a way to change configuration settings on a per-directory basis. In a specific document directory, a file containing one or more configuration directives is placed; the directives are then applied to the directory and all of its subdirectories.
The Apache web server\’s features and functionality can be modified using these.htaccess files.
For illustration:
For URL rewrite, use the.htaccess file.
It is applied to secure the website with a password.
Some IP addresses may be restricted, preventing the site from opening on those IP addresses.
59. What do magic tricks entail?
The member functions are known as \”magic methods\” are accessible to all instances of a class. All magic methods begin with \”__,\” such as \”__construct\” (). It is required to declare all magic methods as public.
A method must be defined within the class or program scope in order to be used. PHP5 uses a number of magic techniques, including:
__construct()
__destruct()
__set()
__get()
__call()
__toString()
__sleep()
__wakeup()
__isset()
__unset()
__autoload()
__clone()
60. What does PEAR in PHP mean?
PHP Extension and Application Repository is referred to as PEAR. PEAR\’s objective is to offer:
A well-organized open-sourced code library for PHP users
a program for maintaining packages and distributing code
a common fashion for writing PHP code
Foundation Classes for PHP (PFC)
Community Extension Library for PHP (PECL)
The PHP/PEAR community\’s website, mailing lists, and download mirrors
61. clarify what soundex() and metaphone().
The soundex key of a string is determined by the soundex() function. An alphanumeric string with 4 characters in length called a soundex key is used to represent a word\’s English pronunciation. Spelling applications can make use of the soundex() function.
<?
php
\”Hello,\” in $str
Soundex ($str); repeat
?>
The metaphone key of a string is determined by the metaphone() function. An English (native) speaker\’s pronunciation of a string is represented by a metaphone key. Spelling applications can also make use of this function.
<?
php
echo \”world\” metaphone;
?>
62. Describe Smarty.
A PHP template engine called Smarty is used. In order to allow for adaptability within the templates, these templates typically include variables (like \”$variable\”) and a variety of logical and loop operators.
63. Describe Memcache.
A web application can access objects really quickly thanks to a technology called memcache, which caches them in memory. It is widely acknowledged as a crucial component in scaling any LAMP and is utilized by websites like Digg, Facebook, and NowPublic.
64. How do we use the command line to run a PHP script?
Assuming php is the command to invoke the CLI program, we simply need to run the PHP CLI (Command-line Interface) program and pass the name of the PHP script file as the command-line argument, for example, php myScript.php.
PHP script may not run correctly in the command-line environment if it was written for the Web CGI interface, so this is something we need to be aware of.