Ans:
Ans:PEAR is a framework and repository for reusable PHP components. PEAR stands for PHP Extension and Application Repository. It contains all types of PHP code snippets and libraries. It also provides a command line interface to install “packages” automatically.
Ans: Static Websites:-In static websites, content can’t be changed after running the script. You cannot change anything in the site as it is predefined.
Dynamic Websites:-In dynamic websites, content of script can be changed at the run time. Its content is regenerated every time a user visits or reloads.
Ans:To execute a PHP script, use the PHP Command Line Interface (CLI) and specify the file name of the script in the following way: php script.php
Ans:The simple and basic difference between PHP4 and PHP5 is PHP4 supports oops concept uses Zend Engine 1 and PHP5 supports oops concept end uses Zend Engine 2.
Ans:
WordPress: WordPress is a free and open-source content management system (CMS) based on PHP & MySQL. It includes a plug-in architecture and template system. It is mostly connected with blogging but supports another kind of web content, containing more traditional mailing lists and forums, media displays, and online stores.
Joomla: Joomla is a free and open-source content management system (CMS) for distributing web content, created by Open Source Matters, Inc. It is based on a model-view-controller web application framework that can be used independently of the CMS.
Magento: Magento is an open source E-trade programming, made by Varien Inc., which is valuable for online business. It has a flexible measured design and is versatile with many control alternatives that are useful for clients. Magento utilizes the E-trade stage which offers organization extreme E-business arrangements and extensive support network.
Drupal: Drupal is a CMS platform developed in PHP and distributed under the GNU (General Public License).
Ans:PHP is sami case sensitive. The variable names are case-sensitive but function names are not. If you define the function name in lowercase and call them in uppercase, it will still work.User-defined functions are not case sensitive but the rest of the language is case-sensitive.
Ans: The popular framework in PHP are:
Ans: PHP has borrowed its syntax from Perl and C.
The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as ‘escaping to PHP’. Escaping a string means to reduce ambiguity in quotes used in that string.
Ans:Some of the important characteristics of PHP variables include:
Ans:
Ans:PHP echo output one or more strings. It is a language construct not a function. So the use of parentheses is not required. But if you want to pass more than one parameter to echo, the use of parentheses is required
Example : void echo ( string $arg1 [, string $... ] )
Ans:PHP print output a string. It is a language construct not a function. So the use of parentheses is not required with the argument list. Unlike echo, it always returns 1.
Syntax:
int print ( string $arg)
Ans:Echo can output one or more strings but print can only output one string and always returns 1.Echo is faster than print because it does not return any value.
Ans:There are 8 data types in PHP which are used to construct the variables:
Integers − are whole numbers, without a decimal point, like 4195.
Doubles − are floating-point numbers, like 3.14159 or 49.1.
Booleans − have only two possible values either true or false.
NULL − is a special type that only has one value: NULL.
Strings − are sequences of characters, like ‘PHP supports string operations.’
Arrays − are named and indexed collections of other values.
Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
Resources − are special variables that hold references to resources external to PHP.
Ans:The following rules are needed to be followed while naming a PHP variable:Variable names must begin with a letter or underscore character.A variable name can consist of numbers, letters, underscores but you cannot use characters like + , – , % , ( , ) . & , etc.
Ans: The rules to determine the “truth” of any value which is not already of the Boolean type are:
Ans:To define a constant you have to use define() function and to retrieve the value of a constant, you have to simply specify its name.If you have defined a constant, it can never be changed or undefined. There is no need to have a constant with a $. A valid constant name starts with a letter or underscore.
Ans: The constant() function will return the value of the constant. This is useful when you want to retrieve the value of a constant, but you do not know its name, i.e., it is stored in a variable or returned by a function.
Ans:
Constants:
Variables:
Ans:
Ans:
Break – It terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.
Continue – It causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
Ans:The final keyword in a method declaration indicates that the method cannot be overridden by subclasses. A class that is declared final cannot be subclassed. This is particularly useful when we are creating an immutable class like the String class.Properties cannot be declared final, only classes and methods may be declared as final.
Ans: We use the operator ‘==’ to test if two objects are instanced from the same class and have the same attributes and equal values. We can also test if two objects are referring to the same instance of the same class by the use of the identity operator ‘===’.
Ans: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 can generate Javascript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.
Ans:It is possible to generate HTML through PHP scripts, and it is possible to pass pieces of information from HTML to PHP. PHP is a server side language and HTML is a client side language so PHP executes on the server side and gets its results as strings, arrays, objects and then we use them to display its values in HTML.
Ans:PHP constructor and destructor are special type functions which are automatically called when a PHP class object is created and destroyed. The constructor is the most useful of the two because it allows you to send parameters along when creating a new object, which can then be used to initialize variables on the object.
Ans: The Include() function is used to put data of one PHP file into another PHP file. If errors occur then the include() function produces a warning but does not stop the execution of the script and it will continue to execute.
The Require() function is also used to put data of one PHP file to another PHP file. If there are any errors then the require() function produces a warning and a fatal error and stops the execution of the script.
Ans : The require() includes and evaluates a specific file, while require_once() does that only if it has not been included before. The require_once() statement can be used to include a php file in another one, when you may need to include the called file more than once. So, require_once() is recommended to use when you want to include a file where you have a lot of functions.
Ans : The different types of error in PHP are:
Ans :There are 3 types of Arrays in PHP:
Ans:Some of the functions in PHP include:
These were some of the most commonly asked basic level PHP interview questions. Let’s move on to the next section of advanced level PHP interview questions.
Ans: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.
Ans: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.
Ans : Cookies are text files with small pieces of data — like a username and password — that are used to identify your computer as you use a computer network. Specific cookies known as HTTP cookies are used to identify specific users and improve your web browsing experience.
Ans : 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.
Ans :They are both variables. But $message is a variable with a fixed name. $$message is a variable whose name is stored in $message. For example, if $message contains “var”, $$message is the same as $var.
Ans : The basic steps to create MySQL database using PHP are:
Ans : The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character.
Ans: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. A callback function is a function that you create yourself, then pass to another function as an argument. Once it has access to your callback function, the receiving function can then call it whenever it needs to.
Ans :In PHP all functions starting with __ names are magical functions/methods. These methods, identified by a two underscore prefix (__), function as interceptors that are automatically called when certain conditions are met. PHP provides a number of ‘magic‘ methods that allow you to do some pretty neat tricks in object oriented programming.
Here are list of Magic Functions available in PHP
_destruct() __sleep()
__construct() __wakeup()
__call() __toString()
__get() __invoke()
__set() __set_state()
__isset() __clone()
__unset() __debugInfo()
Ans :The crypt () function is used to create one way encryption. It takes one input string and one optional parameter. The function is defined as: crypt (input_string, salt), where input_string consists of the string that has to be encrypted and salt is an optional parameter. PHP uses DES for encryption.
Ans :PHP provides a library called cURL that may already be included in the installation of PHP by default. cURL stands for client URL, and it allows you to connect to a URL and retrieve information from that page such as the HTML content of the page, the HTTP headers and their associated data.
Ans : Type hinting is used to specify the expected data type of an argument in a function declaration. When you call the function, PHP will check whether or not the arguments are of the specified type. If not, the run-time will raise an error and execution will be halted.
Here is an example of type hinting–
<?php function sendEmail (Email $email) { $email->send();
}
?>
The example shows how to send Email function argument $email Type hinted at in Email Class. It means to call this function you must have to pass an email object otherwise an error is generated.
Ans : An exception that occurs at compile time is called a checked exception. This exception cannot be ignored and must be handled carefully. For example, if you use FileReader class to read data from the file and the file specified in the class constructor does not exist, then a FileNotFoundException occurs and you will have to manage that exception. For this purpose, you will have to write the code in a try-catch block and handle the exception. On the other hand, an exception that occurs at runtime is called unchecked-exception.
With this, we have come to the end of the PHP interview questions blog. I Hope these PHP Interview Questions will help you in your interviews. In case you have attended any PHP interview in the recent past, do paste those interview questions in the comments section and we’ll answer them. You can also comment below if you have any questions in your mind, which you might face in your PHP interview.
Ans :You can use JavaScript submit() function to submit the form without explicitly clicking any submit button.
Ans : A session creates a file in a temporary directory on the server where registered session variables and their session id are stored. This data will be available to all pages on the site amid that visit.The area of the temporary record is controlled by a setting in the php.ini document called session.save_path.
At the point when a session is begun following things happen -
Ans: Since PHP 4.3, mysql_create_db() function is deprecated. Now it is recommended to use one of the 2 alternatives.
mysqli_query()
PDO::__query()
Ans : Because PHP is a server-side language and Javascript is a client-side language, these two cannot interact. But we can exchange variables since it’s possible to generate Javascript code via PHP, which can be executed by the browser and specific variables can be passed back to PHP via the URL.