Table of Contents
ToggleWhat is PEAR in PHP?
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.
What is cookie and why do we use it?
A cookie is a small piece of information stored in a client browser. It is a technique utilized to identify a user using the information stored in their browser. Utilizing PHP, we can both set and get COOKIE.
What is session and why do we use it?
A session is a super global variable that preserves data across subsequent pages. Session uniquely defines all users with a session ID. So it supports building a customized web application where user tracking is required.
What is PDO in PHP?
PDO stands for PHP Data Object. PDO is a set of PHP extensions that provide a core PDO class and database, specific drivers. The PDO extension can access any database which is written for the PDO driver. There are several PDO drivers available which are used for FreeTDS, Microsoft SQL Server, IBM DB2, Sybase, Oracle Call Interface, Firebird/Interbase 6 and PostgreSQL databases, etc.
It gives a lightweight, vendor-neutral, data-access abstraction layer. Hence, no matter what database we use, the function to issue queries and fetch data will be the same. And, it focuses on data access abstraction instead of database abstraction.
How is it possible to set an infinite execution time for PHP script?
The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded.’ It is also possible to specify this in the php.ini file.
How can you increase the maximum execution time of a script in PHP?
You need to change the value of the max_execution_time directive in the php.ini file for increasing the maximum execution time.
For Example,
if you want to set the max execution time for 130 seconds, then set the value as follows,
max_execution_time = 130
Which function is used in PHP to check the data type of any variable?
gettype() function is used to check the data type of any variable.
Sample cecho gettype(true).”; //boolean
echo gettype(10).”; //integer
echo gettype(‘Web Programming’).”; //string
echo gettype(null).”; //NULLode:
How is the comparison of objects done in PHP?
We use the operator ‘==’ to test is two objects are instanced from the same class and have same attributes and equal values. We can test if two objects are referring to the same instance of the same class by the use of the identity operator ‘===’.
Is multiple inheritance supported in PHP?
PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword ‘extended’.
How can you execute PHP script from the command line?
Answer: You have to use PHP command in the command line to execute a PHP script. If the PHP file name is test.php then the following command is used to run the script from the command line.
php test.php
Is PHP a strongly typed language?
No. PHP is a weakly typed or loosely typed language.
This means PHP does not require to declare data types of the variable when you declare any variable like the other standard programming languages C# or Java. When you store any string value in a variable, then the data type is the string and if you store a numeric value in that same variable then the data type is an Integer.
Sample code:
$var = “Hello”; //String
$var = 10; //Integer
Why do we use PHP?
There are several benefits of using PHP. First of all, it is totally free to use. So anyone can use PHP without any cost and host the site at a minimal cost.
It supports multiple databases. The most commonly used database is MySQL which is also free to use. Many PHP frameworks are used now for web development, such as CodeIgniter, CakePHP, Laravel, etc.
How to send a mail in PHP?
You can send an e-mail in PHP with mail() function or SMTP details.
What is the use of count function in MySQL?
count() function is used for fetching the total number records in a table.
What are tags used?
They allow making the result of the expression between the tags directly to the browser response.
Explain the main types of errors?
The 3 main types of errors in PHP are:
- Notices: Notices are non-critical errors that can occur during the execution of the script. These are not visible to users. Example: Accessing an undefined variable.
- Warnings: These are more critical than notices. Warnings don’t interrupt the script execution. By default, these are visible to the user. Example: include() a file that doesn’t exist.
- Fatal: This is the most critical error type which, when occurs, immediately terminates the execution of the script. Example: Accessing a property of a non-existent object or require() a non-existent file.
What is the use of header() function in PHP?
The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can’t print any HTML element before using this function.
What is the use of session_start() and session_destroy() functions in PHP?
The session_start() function is used to start a new session. Also, it can resume an existing session if it is stopped. In this particular case, the return will be the current session if resumed.
Syntax:
session_start();
The session_destroy() function is used to destroy all of the session variables as given below:
What are the different types of Array in PHP?
There are 3 types of Arrays in PHP:
- Indexed Array – An array with a numeric index is known as the indexed array. Values are stored and accessed in linear fashion.
- Associative Array – An array with strings as index is known as the associative array. This stores element values in association with key values rather than in a strict linear index order.
- Multidimensional Array – An array containing one or more arrays is known as multidimensional array. The values are accessed using multiple indices.
What is the most used method for hashing passwords in PHP?
The crypt() function is used for this functionality as it provides a large number of hashing algorithms that can be used. These algorithms include sha1, sha256, or md5 which are designed to be very fast and efficient.
What is “print” in PHP?
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.
What is NULL?
NULL is a particular type which contains only one value: NULL. If you need any variable to set NULL, just assign it.
What are traits?
Traits are a mechanism that lets you create reusable code in PHP and similar languages where multiple inheritances are not supported. It’s not possible to instantiate it on its own.
A trait is intended to reduce the limitations of single inheritance by enabling a developer to reuse sets of methods freely in many independent classes living in different hierarchies of class.
Tell me some of the disadvantages of PHP?
The cons of PHP are:
- PHP is not suitable for giant content-based web applications.
- Since it is open-source, it is not secure. Because ASCII text files are easily available.
- Change or modification in the core behavior of online applications is not allowed by PHP.
- If we use more features of the PHP framework and tools, it will cause poor performance of online applications.
- PHP features a poor quality of handling errors. PHP lacks debugging tools, which are needed to look for warnings and errors. It has only a few debugging tools in comparison to other programming languages.
What is the meaning of a final class and a final method?
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.
What does PEAR stands for?
PEAR stands for “PHP Extension and Application Repository”. PEAR is a framework and repository for all of the reusable PHP components.
PEAR provides a higher level of programming for web developers. It contains all kinds of PHP code snippets and libraries. It also provides you with a command-line interface to automatically install packages.
Is PHP a case sensitive language?
PHP is partially 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.
How to execute a PHP script from the command line?
To execute a PHP script, use the PHP Command Line Interface (CLI) and specify the file name of the script in the following way:
1.php script.php
How to select a database?
The PHP Data Objects (PDO) is a lightweight, and consistent interface used to access databases in PHP.
What types of loops exist in PHP?
for, while, do while and foreach.
How many types of array are there in PHP?
There are three types of array in PHP:
- Indexed array: an array with a numeric key.
- Associative array: an array where each key has its specific value.
- Multidimensional array: an array containing one or more arrays within itself.
Explain which is required to be able to utilize image function?
The GD library is required to be able to do image functions. It also helps to execute more image functions.
What is the meaning of a final method and a final class?
The final keyword in a declaration of the method indicates that the method cannot be overridden by subclasses. A class that is declared as final cannot be subclassed.
This is especially useful when we are creating an immutable class like the String class. Only classes and methods may be declared final, properties cannot be declared as final.
What is the use of “echo” in PHP?
In PHP, echo is used to print data on the webpage.
Example:
Which function is used in PHP to delete a file?
unlink() function is used in PHP to delete any file.
Sample code:
unlink(‘filename’);
Explain type hinting in PHP?
In PHP, type hinting is used to specify the expected data type (arrays, objects, interface, etc.) for an argument in a function declaration. It was introduced in PHP 5.
Whenever the function is called, PHP checks if the arguments are of a user-preferred type or not. If the argument is not of the specified type, the run time will display an error and the program will not execute.
It is helpful in better code organization and improved error messages.
How to destroy a cookie in PHP?
There is not a way to directly delete a cookie. Just use the setcookie function with the expiration date in the past, to trigger the removal mechanism in your web browser.
What is the use of strip_tags() method?
strip_tags() function is used to retrieve the string from a text by omitting HTML, XML and PHP tags. This function has one mandatory parameter and one optional parameter. The optional parameter is used to accept particular tags.
What is the function mysql_pconnect() useful for?
mysql_pconnect() ensure a persistent connection to the database, it means that the connection does not close when the PHP script ends.
How is it possible to set an infinite execution time for PHP script?
The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded.’ It is also possible to specify this in the php.ini file.
How failures in execution are handled with include() and require() functions?
If the function require() cannot access the file then it ends with a fatal error. However, the include() function gives a warning, and the PHP script continues to execute.
What is the use of the function ‘imagetypes()’?
imagetypes() gives the image format and types supported by the current version of GD-PHP.
How can we create a database using PHP and MySQL?
The basic steps to create MySQL database using PHP are:
- Establish a connection to MySQL server from your PHP script.
- If the connection is successful, write a SQL query to create a database and store it in a string variable.
- Execute the query.
Describe which programming language does PHP parallel to?
The PHP syntax relates Perl and C.
Explain the importance of Parser in PHP?
A PHP parser is software that converts source code into the code that computer can understand. This means whatever set of instructions we give in the form of PHP code is converted into a machine-readable format by the parser.
Explain the difference between static and dynamic websites?
In static websites, content can’t be changed after running the script. You can’t change anything on the site. It is predefined.
In dynamic websites, content of script can be changed at the run time. Its content is regenerated every time a user visit or reload. Google, yahoo and every search engine is the example of dynamic website.
How can PHP and HTML interact?
PHP scripts have the ability to generate HTML, and it is possible to pass information from HTML to PHP.
PHP is a server-side language whereas HTML is a client-side language. So PHP executes on the server-side and gets its results as strings, objects, arrays, and then we use them to display its values in HTML.
This interaction helps bridge the gaps and use the best of both languages.
What are the rules for naming a PHP variable?
The following two rules are needed to be followed while naming a PHP variable:
- It evaluates to FALSE in a Boolean context.
- It returns FALSE when tested with IsSet() function.
How do you display the output directly to the browser?
To display the output directly to the browser, I will use the special tags .
Related Topic :
What is LibreOffice? LibreOffice Impress Features ?