What is PHP?
PHP (Personal Homepage Tool or Hypertext Pre-processor) is a server-side scripting language. It is used in a web application to develop static and dynamic web-based application. Nowadays, PHP is a most used and powerful language, which is widely used for CMS for e.g. Word press, Drupal, Joomla and It is being used in many different Frameworks. It is a free and open source and can download it freely from the PHP official site.
Why PHP?
- It is a free and open source.
- It is easy to learn and runs smoothly on the server side.
- It’s run different platforms E.g: Windows OS, UNIX, Linux OS, MacOS X. It is also called Platform Independent.
- It supports a wide range of database E.g: MySQL, SQL Server, Oracle, etc.
- It is not tag based and is fast and stable.
- PHP can deal with forms, i.e gather information from files, save information to a file, email the data can be sent and return data to the end user
For More:
Can you write basic PHP hello world program or syntax?
Syntax:
<!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
echo '<p>Hello World</p>';
?>
</body>
</html>
Output: <? ='Hello world';
What is PEAR?
PEAR stand for PHP Extension and Application Repository. It is a framework and distribution system for reusable PHP components. PEAR is a community-driven project governed by its developers.
What is PECL?
PECL stands for PHP Extension Community Library. It is a separate project that distributes PHP extensions. PECL extensions are also distributed as packages and can be installed using the PEAR installer with the pecl command.
What is the related PHP programming language resembled?
What are the main features in PHP 7?
PHPNG stands for PHP Next Generation is the refactored Zend engine, which aims to offer better performance and was used as the basis for PHP7.
- Memory Consumption
- Unicode code point Escape syntax
- Depractions of Mysql_ functions
- Anonymous classes
- Expectations
- Added new operators: Null Coalesce Operator (??) and Spaceship
- Declaring The Return Type
- preg_replace_callback_array ()
- Return type Declaration and scalar type Declaration
- Group Use Declaration
- CSPRNG Functions
- Error handling and 64 bit support
- Class member access on cloning has been added
What are major differences between PHP5 and PHP7?
- Speed: PHP7 consistently show speeds twice as fast as PHP 5.6 and many times even faster.
- In PHP 5, a listen directive with only a port number would listen on all interfaces, but only on IPv4. PHP 7 will now accept requests made via both IPv4 and IPv6.
- In PHP5, the programmer cannot define the return type of function, But PHP7 allows programmers to declare the return type of the functions as per the expected return value
- PHP5 does not support 64-bit, PHP 7 supported 64-bit.
- If the code is written in PHP 5.5 or 5.6, then upgrading to PHP 7 will be real easy.
- In PHP 5.6, the bug which makes the switch statement to have multiple default classes is now (In PHP7) fixed.
Can you explain Anonymous Classes in PHP7?
Anonymous classes are those classes that don’t have any name in PHP7. These anonymous classes are defined using the new class. It can replace the full-class definition. When simple, one-off objects are created then anonymous classes are useful. They are internally generated names so we don’t have to give names to these classes. Objects created by the same anonymous class are instances of that class.
How do you execute a PHP script from the command line?
Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows:
php script.php
What is a null coalescing operator in PHP7?
Null coalescing operator is a new feature added to PHP7. It strictly checks for null or non-existent variable or index. This function is used to replace the ternary operation in conjunction with isset() function and it also returns its first operand if it exists and is not null. Otherwise, it returns the second operand.
How can PHP and Javascript interact?
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 is able to generate JavaScript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.
How will you send an email using PHP?
PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient’s email address, the subject of the message and the actual message additionally there are other two optional parameters.
mail( to, subject, message, headers, parameters );
Can you define Easy User-land CSPRNG?
User-land refers to an application space that is external to the kernel and is protected by privilege separation, API for an easy to use and reliable Cryptographically Secure PseudoRandom Number Generator in PHP.
What is Zend Engine?
The Zend Engine is used internally by PHP as a compiler and runtime engine. The PHP Scripts are loaded into memory and compiled into Zend opcodes and these opcodes are executed and the HTML generated is sent to the client.
How to run the interactive PHP shell from the command line interface?
Just use the PHP CLI program with the option – an as follows:
php -a
What is the difference between Public, private and protected in PHP?
Public: The items which are declared public can be access from everywhere ie access from inside the class, access in inherited class and access from outside the class.
Private: The items which are declared private can only be access inside its class that defines the item.
Protected: The items which are declared protected can be access inside the class that defines the item and can access in its child classes (ie access in its inherited class).
For More:
What is spaceship operator?
It is Operator which is used to compare two expressions.
It return -1, 0 or 1.
Can you explain connect a MySql database using PHP?
PHP provides mysql_connect function to open a database connection.
connection mysql_connect(server,user,passwd,new_link,client_flag);
What is the use of unlink ()function?
The unlink() function is dedicated for file system handling. It simply deletes the file given as entry.
What is the use of the function imagetypes()?
imagetypes() gives the image format and types supported by the current version of GD-PHP.
What is the use of dirname() function?
The dirname() function is used more often than you would think. It is the ideal function to refer to directories in a relative way. As of PHP 7, the dirname function has a second argument that indicates how many levels you’re going up the directory tree. If you don’t enter a value, 1 is the default.
What is the use of unset() function?
The unset() function is dedicated for variable management. It will make a variable undefined.
Can you explain PHP magic constants?
PHP provides a large number of predefined constants to any script which it runs known as magic constants.
What is use of Closure::call() in PHP7?
It is used to temporarily bind an object scope to a closure and invoke it.
Can you explain set cookies using PHP?
PHP provided setcookie() function to set a cookie. This function requires upto six arguments and should be called before <html> tag. For each cookie this function has to be called separately.
What extension are removed ?
ereg
mssql
mysql
sybase_ct
Explain set cookies in PHP?
Setcookie(“sample”, “ram”, time()+3600);
Which library needed to be able to use image function?
GD library is needed to be able execute image functions.
What does the PHP error Parse error in PHP – unexpected T_variable at line x means?
This is a PHP syntax error expressing that a mistake at the line x stops parsing and executing the program.
Explain how preg_split function works?
The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
What is the purpose of _FILES variable in PHP?
This is a global PHP variable. This variable is an associate double dimension array and keeps all the information related to the uploaded file.
What are the methods possible display texts with a PHP script?
Two methods are possible:
1 <!--?php echo "Method 1"; print "Method 2"; ?-->
What is the use of namespace in PHP?
Namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions: Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.
Can you possible to set an infinite execution time for PHP script?
set_time_limit — Limits the maximum execution time: 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.
Write Unicode codepoint escape syntax?
Syntax:
echo "\u{aa}";
echo "\u{0000aa}";
echo "\u{9999}";
output:
ª
ª (same as before but with optional leading 0’s)
What is Throwables in PHP7?
Another change in PHP 7 is the fact that errors are no longer raised the way they used to be raised. Errors now behave in a similar way as exceptions. They both inherit from the Throwable interface. It means that errors can now be caught in a try/catch block. You can catch both exceptions and errors as Throwables, but you can also catch errors as Error objects.
Can you explain given variable alphanumeric or not?
It is possible to use the dedicated function, ctype_alnum to check whether it is an alphanumeric value or not.
Can you explain access the data sent through the URL with the GET method?
In order to access the data sent via the GET method, we use $_GET array like this:
www.url.com?var=value
$variable = $_GET[“var”]; this will now contain ‘value’
Explain how failures in execution are handled with include () and require () functions?
If the function require() cannot access to the file then it ends with a fatal error. However, the include () function gives a warning and the PHP script continues to execute.
Can you explain mysql_pconnect function?
mysql_pconnect — Open a persistent connection to a MySQL server. This function returns the connection on success, or FALSE and an error on failure. You can hide the error output by adding an ‘@’ in front of the function name.
Syntax:mysql_pconnect(server,user,pwd,clientflag)
What function gives us the number of affected entries by a query?
mysql_affected_rows() return the number of entries affected by an SQL query. This function returns the number of affected rows on success, or -1 if the last operation failed. Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier.
What is the difference between unset() and unlink() function in PHP?
The unset() function is used to destroy a variable and the unlink() function is used to destroy a file.
What are the encryption functions in PHP?
Encryption functions are: CRYPT() and MD5().
What is the syntax to send a mail in PHP?
In PHP mail () function is used to send emails.
Syntax:
mail (to , subject ,message ,headers, parameters);
What is type hinting?
Type hinting is the function specifies what type of parameters must be and if it is not of the correct type an error will occur.PHP 5 introduces type hinting and the functions are able to force the parameters to be objects, interfaces , array.
What does ob_start do?
Makes it so PHP does not output anything. Companies ask this because many large frameworks wrap a bunch of code in ob_start() and ob_get_clean(). So understanding how that function works is pretty important.
what is the use of ksort function?
The ksort is used to sort an array by key in reverse order.
What does _FILES means in PHP?
The $_FILES is an associative array composed of items sent to the current script via the HTTP POST method.
What are the different types of errors in PHP?
E_ERROR: A fatal error that causes script termination
E_ALL: Catches all errors and warnings
E_PARSE: Compile time parse error.
E_WARNING: Run-time warning that does not cause script termination
E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
E_NOTICE: Run time notice caused due to error in code
E_USER_WARNING: User-generated warning message.
E_USER_NOTICE: User-generated notice message.
E_USER_ERROR: User-generated error message.
E_STRICT: Run-time notices.
Hello. A debt of gratitude is in order for Posting this data. I simply need to tell you that i simply look at your site and I think that its exceptionally fascinating and useful.