bookmark_border​How to check DNS records using PHP

PHP is a very useful programming language, and you can use it, instead of the built-in commands like the Dig command, for querying DNS records. Do you want to know how to check DNS records using PHP? It is a simple process, and there are different PHP functions that you can use. Let’s see them.

​PHP functions for checking DNS records

There are several functions that can be used for checking DNS records. For example, some can check just if the DNS records exist, others serve for only a specific type of DNS record, and others can show any type.

  • checkdnsrr() – This query will see if DNS records exist for the host (hostname or IP address).
  • dns_get_record() – Get the DNS record for the host (hostname or IP address). It could be any type of DNS record.
  • getmxrr() – Get the MX DNS records only, for the host (hostname or IP address).

​checkdnsrr() function 

This will check many different types of DNS resource records. You can specify it with the following parameters: 

  • host – hostname or IP address.
  • type – The particular type of DNS record that you are interested in, like A, AAAA, MX, SOA, NS, CNAME, SRV, TXT, ANY (show all), or another.

The result will be just an answer if there is such a record (“1”) or there is no such a record (“0”). 

Code example:

<?php

$all_records_check = checkdnsrr ( ‘google.com’, ‘ANY’ );

echo $all_records_check;

?>  

This will check the host google.com for any type of DNS records, and the result is that it does have DNS records (“1”). 

<?php  

$mx_records_check = checkdnsrr ( ‘google.com’, ‘MX’ );

echo $mx_records_check;

?>  

This will check the host google.com for MX DNS records, and the result is that it does have MX records (“1”).

​dns_get_record() function

This PHP function will serve you if you actually need to check the content of the DNS records. It will retrieve the DNS record or records that you asked for from the DNS name server. You have a few parameters that we can use as before:

  • hostname – Here, you can put the hostname like “google.com”. 
  • type – With this parameter, you can specify the type of DNS record that you want to get. Here are some of them that you can use: DNS_A, DNS_AAAA, DNS_CNAME, DNS_HINFO, DNS_SOA, DNS_NS, DNS_PTR, DNS_MX, DNS_TXT, DNS_SRV, DNS_NAPTR, DNS_A6, or DNS_ANY.
  • authns – This will populate the authoritative name server with recource records.
  • addtl – This will populate the authoritative name server with aditional records.
  • raw – Query only the requested type of DNS record, instead of looping type by type before going with the additional information.

This is probably the most used PHP function for checking DNS records because it will return you the actual DNS records. Not like in the previous case, just a confirmation if they exist or not. 

Code example:

<?php  

$get_any_records = dns_get_record(“google.com”, DNS_A+DNS_NS);

print_r($get_any_records);

?>

In this case, we are checking google.com for the A records and the NS records.  

​getmxrr() functions

This works only with MX records. This function will get us the MX records for the domain name we are checking. The parameters that can be used with this are below:

  • hostname – The hostname of the target
  • mxhosts – Here, we will see an array of all the available MX records that the query can find. 
  • weight – With this one, it will show the weight information it can find about the order. 

Code example:

<?php

$get_mx_records = getmxrr(“google.com“, $mx_array);

print_r($mx_array);

?>

With this code we will see the MX records for google.com, organized in an array.

​Conclusion

PHP serves to get DNS records. It is very easy to use. Try the functions that we mentioned before with the hostname that you need and the particular DNS records. 

bookmark_borderPHP vs. Python: What is the difference?

What is PHP?

PHP, short for Hypertext Preprocessor, is an open-source, server-side scripting and programming language. The primary usage of it is for web development. However, PHP is a very important language for everybody involved in some way with WordPress. The reason for that is because PHP is used for the majority of the core WordPress software. Many people think that PHP as a programming language is not in use anymore, but actually, that is not quite true.

PHP has different versions, which you can benefit from by installing them on your server. The brand new PHP 7.4 and PHP 8.0 come with a lot of new performance improvements rather than the older versions.

It is essential to choose the most recent versions of PHP not only for performance improvements but also for better security.

What is Python?

Python is a common general-purpose programming language. It is also very well known, and it is possible to be applied for a great range of types of applications. In addition, Python offers for its users dynamic typing, high-level data structures, and a lot of other features. All of these benefits are the reason why Python is used for complex application development, being for scripting or, in other cases, for connecting components together, performing like “glue code.” 

In some cases, it can be extended and put in use for performing system calls to nearly any operating system. Also, in addition, to run a code that was written in C or C++.

Thanks to its universality and capability on almost any system architecture, Phyton is a great choice. So that helps for it to be a universal language and to be seen used in all kinds of various applications.

PHP vs. Python

  • PHP is for Hypertext Preprocessor applied to develop a dynamic website or web application. On the other hand, Python is a high-level object-oriented programming language that is applied for accelerated application development.
  • PHP is usually the choice for a language when we are talking about web development. In the other case, Python is commonly applied in data science, AI, and scientific society.
  • PHP holds a number of frameworks, and Python has a pretty small amount of frameworks.
  • When we are analyzing PHP vs. Python for web development, PHP has an extensive variety of syntax and naming conventions. On the other hand, Python appears with a very concise and precise syntax of codes.
  • The key features of PHP are open source, constant improvements, and simple deployment. For Python, the key characteristics are dynamic typing and rapid development.

Which one to choose?

For sure, deciding which one to choose, PHP vs. Python, is an assuredly not so easy job, even after analyzing the differences between them. The reason is that both of them, PHP vs. Python are great options in their own specific way. Like we mentioned, PHP is applied for web development and server-side scripting. In the other case, Python is the gateway to machine learning codes.

bookmark_borderHow to use PHP code in Linux command line?

You can use PHP code thanks to the CLI SAPI (command-line interpreter/interface Server Application Programming Interface). It can serve you for developing of shell application with PHP, straight from the command line of your Linux computer. 

You can use PHP code in the Linux command line in 3 different ways.

1. Use PHP to execute a specific file.

Let’s say we have a PHP script that is called my_script.php. We can execute it with the following command: 

$ php my_script.php

or 

$ php -f my_script.php

You can use “php” or the “-f” switch. Having the php extension at the end is not required. 

2. Directly pass the PHP code to execute on the command line. 

$ php -r ‘print_r(get_defined_constants());’

You need to be especially careful with shell variable substitution and usage of quotes. In this case, we are using the “-r” switch that does not need tags for beginning or ending. If you add those tags, that will lead to an error. 

3. Execute PHP code via standard input (stdin). 

You can create PHP code dynamically and put it in the binary. See the example below: 

$ some_application | some_filter | php | sort -u > final_output.txt

The PHP binary accepts different arguments, plus the PHP script can receive more arguments. The arguments are not limited by PHP. The arguments are available in the global array $argv (Array of arguments passed to script). The first index should contain the script’s name and the way you are calling it from the command line. If you are using the second (-r) or the third way (stdin), the value of $argv[0] will be “-“. 

$argc, a second global variable, has the number of elements in the array $argv. 

In case the arguments passed to the script do not start with “-“, there is nothing extra to think about. If the character exists, the interpreter will try to handle it, even before the script. You can evade troubles with list separator “–”

# This will not execute the given code but will show the PHP usage

$ php -r ‘var_dump($argv);’ -h

Usage: php [options] [-f] <file> [args…]

[…]

# This will pass the ‘-h’ argument to the script and prevent PHP from showing its usage

$ php -r ‘var_dump($argv);’ — -h

array(2) {

  [0]=>

  string(1) “-“

  [1]=>

  string(2) “-h”

}

Use PHP code on Unix-based system.

Here you will need to take care of one important thing – add the path to the PHP CLI with “#” sign before – #!/usr/bin/php

 Apart from this, everything should work fine. 

Example of PHP script executes as a shell script

#!/usr/bin/php

 <?php

 var_dump($argv);

 ?> 

We asume we are at the current directory and we have a test file: 

$ chmod +x test

$ ./test -h — foo

array(4) {

  [0]=>

  string(6) “./test”

  [1]=>

  string(2) “-h”

  [2]=>

  string(2) “–“

  [3]=>

  string(3) “foo”

}

No worries about the “-” sign. 

In the beginning, the special “#!” shows to the system which program it must use to run it. 

On Windows, you can associate double-click on a .php extension with the php.exe. If the script starts with “#!” it does not bother Windows users because it just takes it as a comment. 

Example of script (script.php), ment to be run from the command line:

#!/usr/bin/php

 <?php

 if ($argc != 2 || in_array($argv[1], array(‘–help’, ‘-help’, ‘-h’, ‘-?’))) {

 ?>

 This is a command-line PHP script with one option.

   Usage:

   <?php echo $argv[0]; ?> <option>

   <option> can be some word you would like

   to print out. With the –help, -help, -h,

   or -? options, you can get this help.

 <?php

 } else {

    echo $argv[1];

 }

 ?>

The program will first check for a required argument (after checking the script name). If there is no argument or there is “–help”, “-help”, “-h”, or “-?” it will print the help message. 

bookmark_borderShould you update to PHP 8?

Yes, you definitely should update to PHP 8, if you are using an older version. There will be many new features, regardless of the version you are coming from. What should you expect?

When was PHP 8 introduced? 

PHP 8 (version 8.0.0) arrived on the 26th of November, 2020. What you should really check about it is the JIT, Named Arguments, Union Types, Match Expressions, Constructor Property Promotion, Nullsafe Operator, Error Handling, and more.

Since then, there have been a few minor upgrades, mainly focusing on stability and bug fixing:

PHP 8.0.1 – 07.01.2021

PHP 8.0.2 – 04.02.2021

PHP 8.0.3 – 04.03.2021

PHP 8.0.5 – 29.04.2021

PHP 8.0.6 – 06.05.2021

PHP 8.0.7 – 03.06.2021

PHP 8.0.8 – 01.07.2021

PHP 5 to PHP 7.2, should you update?

Yes, you should update if you are using any version previous to PHP 7.3. We do not even mention all the new features and bugs fixed that you will get with the new version. The main reason is that the support for all previous versions up to PHP 7.3 is over. They are outdated, and you must update them for better security and compatibility.

Should you update from PHP 7.3 or 7.4 to PHP 8?

The answer is yes. The official support of PHP 7.3 will finish on 06.12.2021, which is getting closer, and those of you who are using 7.4 should consider updating for the new features. Still, if you are on version 7.4, you can use it without problems until 28.11.2022 and get support. By then, PHP 8 will be in its PHP 8.1 version (expected on 25.11.2021), and you can get an even safer and stable version.

What will you get with the new version?

These are the reasons that you should update to the new version 8:

JIT (Just-in-time) compiler. “PHP JIT is implemented as an almost independent part of OPcache. It may be enabled/disabled at PHP compile time and at run-time. When enabled, native code of PHP files is stored in an additional region of the OPcache shared memory and op_array→opcodes[].handler(s) keep pointers to the entry points of JIT-ed code.”

Thanks to the Opcache, the need to load and parse scripts per request is lowered, and that way, you save time and CPU usage.

Constructor Property Promotion – a simplified method for declaring properties. It will lower the repetition of properties and makes it easier to use with objects. A simpler syntax is better for the coders.

Named Arguments – they pass an argument to a function based on the parameter’s name, not its position. Add arguments to a function just by adding the parameter’s name before the value.

Match Expressions – it is similar to the “switch”, but it allows return values, and the new match expression makes identity check comparison (===) instead of a loose comparison (==).

Union Types – it is a useful feature that can unite 2 or more types and show that any of them can be used. In the previous version, the way was to specify union types was only in phpdoc annotations.

Nullsafe operator – with the nullsafe operator, we can finally have behavior like the one of the coalescing operator, on method calls. Use the previously known coalescing operator with array keys and the new nullsafe operator with method calls.

Attributes. They are used to specify different properties for objects, elements, and files in metadata (annotations). Before, you could add metadata only by adding doc-comments.

How to migrate?

You can find a guide on the PHP site, depending on the version you are using. Follow it and see what’s new you will get and if there might be any incompatibilities.

bookmark_borderHow to update PHP 5 to 7?

Updating is never 100% painless, but the team behind PHP has tried its best to lower the incompatibilities and provide a good experience during the process of updating from PHP 5 to 7. 

Migration tools 

Before moving your application from PHP 5 to 7, you should most definitively back up. You don’t want to lose your work. You can also use various migration tools that can tell you in advance what part of the code most probably won’t work and how to fix it. Check one of these 3: 

PHP 7 MAR

php7mar is a simple tool that generates reports. It will show which line of code has a problem, put a note and suggest a course of action. 

PHP 7 Compatibility Checker

php7cc is another similar tool for compatibility checking. It will show errors in red, which could be fatal, syntax, or notices. It will also display warnings in yellow. 

PHPto7aid

php7aid is showing directly what part of your PHP 5 code won’t work. It will try to help you resolve the problems. 

Updating PHP 5 to PHP 7 on Linux

In this step-by-step guide, we will update PHP 5 to PHP 7 on an Ubuntu computer running LEMP (Linux, Nginx, Mysql, PHP) and a user with sudo permissions. 

Before installing or updating, we need to add the repository, which contains PHP 7 for Ubuntu. Use the following command:

sudo add-apt-repository ppa:ondrej/php 

The Terminal will show you a description of the repository. Press Enter and continue. 

Then you will need to check for updates with this command:

sudo apt-get update

 Finally, we can install PHP 7 with the following command:

sudo apt-get install php7.0-fpm php7.0-mysql 

After the installation of the PHP 7, change the path to the fastcgi_pass to the new PHP 7. You need to change “/var/run/php5-fpm.sock” to “/var/run/php/php7.0-fpm.sock”. The result should look like this:

location ~ \.php$ {

 try_files $uri =404;

 fastcgi_split_path_info ^(.+\.php)(/.+)$;

 fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

 fastcgi_index index.php;

 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

 include fastcgi_params;

 } 

Now that we are ready, restart the Nginx:

sudo service nginx restart 

Ready! 

Updating PHP 5 to PHP 7 on macOS

To update PHP 5 to 7 on macOS, we are going to use Homebrew. If you don’t have Homebrew installed already, you can follow these steps to get it. 

Open the Terminal application. 

Paste the following command onto the Terminal and press Enter: 

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)” 

Press Enter again to agree and then enter your username and password. 

Now you are ready to use Homebrew.

Again, inside the Terminal, you will need to use a few commands:

brew install openldap libiconv

brew tap exolnet/homebrew-deprecated

brew unlink php56

brew install [email protected]

There are no older versions left inside Homebrew’s repositories, so here we are installing directly PHP 7.4 that is still available. In this case, we have unlinked an older version PHP 5.6, before installing the new one. If you have another previous version, you can unlink it. 

Updating PHP 5 to PHP 7 on Windows

If you are a Windows user and you are using XAMPP or WAMP, just update your software. The newer version will have the latest PHP version. You can also go to their websites and download the right version for you. There you can see with which PHP version they are coming before downloading and installing them. 

Updating on CentOS, Fedora, Red Hat

For those of you running any of these OSes, you will need to follow these commands: 

sudo yum update

rpm – Uvh https://dl.fedoraproject.org/pub/epel/epel/epel-release-latest-7.noarch.rpm

rpm – Uvh https://mirror.webtatic.com/yum/e17/webtatic-release.rpm

sudo yum install php70w

sudo yum install php70w-mysql

Consider updating from PHP 5 to PHP 8 directly. 

There will be support for PHP 7.3 until 06.12.2021 and PHP 7.4 until 28.11.2022. Consider making the jump directly to PHP 8 so you can get the newest features and longer support. 

bookmark_borderWhat is the difference between PHP 5 and PHP 7?

The Hypertext Preprocessor (PHP) is a very popular scripting language. It’s been a standard since 1994 due to its attractive features. Safer connectivity to the database, faster speed, runs smoothly on the most used platforms (Windows, Unix, Linux). Of course, there were many improvements, but let’s have a closer look at PHP 5 and PHP 7.

PHP 5 main features.

PHP5 was developed considerably more robust than PHP 4. The Zend II engine powered it. It offered an improved mechanism for handling exceptions and errors, a model oriented to objects that supplies interfaces, abstract classes, constructors, static and final properties. Besides, it had SSL connections, multi-query functions for MySQL extension. PHP5’s XML extensions were enhanced, just like the soap implementation for providing and consuming web services, speed, and performance.

PHP 7 main features.

PHP 7 was the successor of PHP 5. Its performance was better than the PHP 5. It was powered by a PHP-NG (Next Generation) engine. It achieved twice the PHP 5 performance and 50% less memory consumption to give a reference. It added anonymous classes, removal of deprecated methods, better exception hierarchy and handling, more efficient memory use, abstract syntax tree, and support for return type declarations. Besides, it included scalar type declarations for better controlling the code, CSPRNG functions, spaceship operator (three-way comparison), constant arrays using define (). 

What is the difference between PHP 5 and PHP 7?

  • Performance. And PHP 7 speed got double than the one offered by PHP 5. While PHP 5 (Zend II engine) handled an average of 22 requests per second, PHP 7 (PHP-NG engine) made 44. So PHP 7 totally boosted the scripting performance and websites’ loading speed.
  • Exception handling. Handling fatal errors with PHP 5 was hard for developers, mostly because errors were not displayed directly. You needed to trace the information to find it and to identify if it was fatal or not for an application. On PHP 7, important errors became exceptions to be caught easier.
  • Return type. PHP5 didn’t include a provision for return type declarations. This feature was added to PHP 7 version, making the code more accurate. The available return types were: float, string, bool, int.
  • Null coalescing operator ?? On PHP 5, you had to write explicit code to return the null value in the case the value was not available (it didn’t exist). On PHP 7, you could just use the operator ?? (two question marks) to return a variable’s value if it was available or for returning null if it was not available.
  • Spaceship operator (combined or three-way comparison). With PHP 5, many different operators were used for comparing. PHP 7 integrated the three-way comparison operator (<=>), meaning that with a single operator, three kinds of comparisons were possible to do simultaneously: greater than, less than, and equal. It returned 0, meaning equal, -1 if the right part was greater than the left, and 1 in the opposite scenario.
  • Declarations. PHP 5 worked with individual declarations for namespaces. PHP 7 simplified the task through the use of group declaration. This made code more compact and easy to read. It definitely meant less time typing for programmers. 
  • 64-bit support. While PHP5 didn’t support 64-bit, PHP7 did, the complete 64-bit and large files. Running applications smoothly on these architectures was not a problem anymore.
  • Anonymous class. It was included on PHP 7. Then, creating a complete definition of a class required just once in the whole application was not needed anymore. Instead, an anonymous class for a single-use got possible. 

Conclusion.

The jump from PHP 5 to PHP 7 was key for PHP to evolve and become a more useful scripting language. Currently, we are on PHP 8 (8.0.8 version). Stop imagining the possibilities. Better experience them now!

bookmark_border​Why is there no PHP 6?

For computing experts and coders, this is not a mystery. However, for people getting their first approach to Hypertext Preprocessor (PHP), the jump between PHP 5 and PHP 7 can seem strange. Let’s see what exactly happened with this missing version. 

​Why is there no PHP 6?

There is not PHP-6 because it was never released. Its original plan didn’t work as expected. To avoid confusion and not relate new developments (versions) to an unsuccessful experience and negative opinions, the decision was to jump directly from PHP 5 to PHP 7.

​What was the original plan?

The functionality of the PHP scripting language made it really popular among coders. Therefore, the development of new and enhanced versions has kept going since its original release in 1994. Rasmus Lerdorf, its creator, and soon more enthusiast coders joined the effort to improve PHP.

In 2005, PHP 5 was in use, and planning for the next version’s development started. Enthusiasm was big, and plans were ambitious. PHP 6 would include native Unicode support in the API, engine, and extensions. Therefore, no external libraries would be needed, very few conversions required, and language bias would be avoided.

Besides:

  • The safe_mode, together with the “register_globals” function, would be deleted.
  • A new 64-bit integer type was considered.
  • A traits feature for horizontal reuse of the language.
  • Additional static typing features.
  • A goto keyword, avoiding the goto name but adding target labels to break.

What went wrong with PHP 6? 

Efforts to achieve these goals were hard. Especially the Unicode conversion took much longer than expected. And finishing this was key, the base for adding the rest of the new features. As a reference, in 2011 PHP 6 Unicode conversion task advanced around 70%.

To run a website without Unicode is hard, and your coders know it. Supporting Unicode is possible until a certain point, even in case the used language is not compatible with Unicode, but errors are easy to get. It’s not an easy task. 

Accurate support for Unicode demands a language that can understand Unicode strings. And as we mentioned before, PHP 6 ambitious plan was to support it completely (API, engine, and extensions).

To achieve the goal and make compatibility possible with the International Components for Unicode (ICU) library, using the two-byte UTF-16 encoding for all the strings inside PHP was decided. It sounded logical since ICU’s system used it, and interactions inside ICU were calculated to be more than with outside players like disk files or MySQL. 

Rephrasing, for coders, reading or writing a string from an outside source usually happens once. But many Unicode actions can be required on the same string. A conversion for every action multiplies the job. So to use the two-byte UTF-16 encoding looked like a proper solution, at least in theory.

Unfortunately, the decision was not as useful as expected in practice, and its cost went really high. Still, other conversions were needed to do, for instance, script code, request data, database results, etc., from UTF-8 to the UTF-16. And such conversion demanded more CPU processing. A UTF-8 string required half the memory that UTF-16 took. Besides, due to the conversion, sometimes manual checks were needed to identify the exact location of an error. It could be either in the original encoding or in the converted one.

What happened with PHP 6?

Unicode support became the PHP 6 Achilles heel. No matter the effort, opinions about it were negative. Its performance was qualified as poor, broken scripts were constant, and memory usage went high. 

In March 2010, the development of PHP 6 officially stopped. Its features not related to the Unicode were transferred to the new PHP 5.4. 

bookmark_borderPHP 7 explained

PHP 7 explained

PHP 7 is a significant release of PHP programming language. It is promoted as a revolution. As for how web applications are possible to be developed and produced for the cloud and mobile to enterprises. This particular release is pointed to be the most significant improvement for PHP after the announcement of PHP 5 in 2004. 

Initiation of the development of PHP 7

The initiative for the development of PHP 7 came from Dmitry Stogov, Xinchen Hui, and Nikita Popov. These three developers designed a test branch of PHP that they first named PHP Next Generation (PHPNG). The PHP community embraced it, as it had crucial performance improvements. It continued to develop into a well-built version now known as PHP 7. After some months of beta testing, the official release was in December 2015.

What Drove the Need for PHP 7?

The PHP language is extremely popular. Rasmus Lerdorf created it in 1994. Since then, it has gained popularity, and now approximately 82 percent of websites implement PHP. That indicates that most of the Web is relying on this language. In addition, the amount of people online is continuing to increase. This includes the rapidly growing number of mobile users. Therefore, the servers that power the world’s websites are necessary to be able to respond fast to user requests. Speed is an essential factor in the design of a website. People are going to leave a web page that takes a lot of time to load. 

The PHP changes boosted the performance of sites dramatically. It is estimated that version 7 gives a 100 percent increase in performance speed compared to version 5.6. This allows the developers to make websites that present attractive and interesting interactive traits that can also respond to visitors’ input fast. 

The development of this version was also motivated by the need for scripting languages that work more efficiently. The desire for that is inspired by two things: the need to decrease power consumption to protect the ecosystem and the need to reduce expenses.

It reduces the demands on the servers, which makes it more friendly for the environment and more cost-effective decision. In addition, compared to PHP 5.6, running PHP 7 applications needs less energy to power servers.

New Features

To PHP 7 are added a lot of new features. The most significant ones from them are the following: 

  • Improved performance − It is twice faster than PHP 5 when you have a PHPNG code united in PHP 7.
  • Scalar type declarations − Now, return types and parameters are able to be implemented.
  • Less Memory Usage − The optimized PHP 7 consumes a lot lesser resources.
  • Exception hierarchy − The feature is improved.
  • 64-bit support − 64-bit architecture machines receive constant support.
  • Several fatal errors converted to Exceptions − The variety of exceptions is extended. Including many fatal errors turned into exceptions.
  • Null coalescing operator (??) − A new feature is applied to replace the ternary operation in conjunction with the isset() function.
  • Secure random number generator − Increase of the latest secure random number generator API.
  • Return and Scalar Type Declarations − Added support for the return type and parameter type.
  • Deprecated SAPIs and extensions removed − Several past and unsupported SAPIs and extensions are eliminated from the PHP 7 version.
  • Anonymous Classes − It is added support for anonymous.
  • Zero cost asserts − Also added support for zero cost asserts.

PHP 7 applies new Zend Engine 3.0. The purpose is for the performance of the application to improve twice. Also, the consumption of memory to be 50% better than PHP 5.6. This allows without any extra hardware to work for more concurrent users.

PHP 7 is created contemplating today’s workloads.

bookmark_borderPHP Version 5 – everything you need to know

PHP 5

PHP 5 was released on 1 July 2004. That is 4 years after introducing PHP 4 to the scene of the Internet. The aim is to bring a lot of new functionalities to the PHP language. The focus of the team was on what is not very well supported and what is missing in the previous versions. The focus of the new PHP 5 version is on 3 major areas: Object-Oriented programming, XML, and MySQL support.

Object-Oriented programming

This feature was present in PHP 4, but in PHP 5 it is introduced an entirely reworked object model. It now offers:

  • Interfaces
  • Destructors
  • Constructors
  • Protected, private, and public properties and methods
  • Class type hints
  • Abstract classes
  • Final properties and methods
  • Static properties and methods
  • Magical methods

Programmers in PHP 5 are able not just to pass objects by value but also by reference.

Reworked MySQL extension

The MySQL extension is completely reworked in PHP 5. It provides support for MySQLi, which is the new version of MySQL. It means MySQL improved. This new extension offers:

  • Bound input and output parameters
  • Prepared statements
  • SSL connections
  • MySQL can now apply PHP’s new OO model
  • Multi-query functions

Reworked XML extension

XML tools were great for the job in PHP 4. Except, they were not actually designed to operate together, and often patches were necessary to complete the required functionality. In PHP 5 is applied a reworked XML parser with tools capable of operating with one another. Furthermore:

  • They are included in a single XML library: libxml2.
  • XML extensions can operate together as a whole.
  • They provide efficient data processing. 
  • XML extensions can provide you with the exact XML tool for the task.
  • They comply fully with W3 specifications.

The SimpleXML extension is also introduced in PHP 5. It allows you to handle the data in XML documents easily. It treats it as an array and looping through it.

Release history of PHP 5

5.0 version. PHP 5 was released powered by Zend Engine II with a new object model.

5.1 version. For accessing databases was added PHP Data Objects (PDO) as a lightweight, consistent interface. Improvements in performance with the introduction of compiler variables in re-engineered PHP Engine. 

5.2 version. Native JSON support. The filter extension is enabled by default. 

5.3 version. New features are Namespace support, late static bindings, jump label. Also, the Windows support is improved. Further added features like, sqlite3, and mysqlnd replacing libmysql as an underlying library for the extensions that operate with MySQL.

5.4 version. New features are trait support and short array syntax support. In addition, some improvements are made to the current performance and features, plus decreased memory requirements.

5.5 version. Further support for generators and finally blocks for exceptions handling. OpCache (based on Zend Optimizer+) in a set in the official distribution.

5.6 version. Constant scalar expressions, possible large file uploads, new interactive “phpdbg” debugger as a SAPI module, and other more minor improvements.

Is PHP 5.6 still supported?

If we have to give a short answer, it is “No.” This is because PHP developers are no longer supporting PHP 5.6 or any other version of PHP 5. On 31 December 2018, officially ended the support of PHP 5.6. 

Furthermore:

  • There won’t be any more security updates.
  • There won’t be any more bug fixes.
  • In a production environment, you should not use PHP 5.6 or any version of PHP 5. 
  • For security reasons, you should no longer use PHP 5. There are many out-of-date libraries and functions.

bookmark_borderHistory of PHP programming language

PHP, or also called Hypertext Preprocessor, is the most popular server-side scripting language. It is incredibly adaptable and holds plenty of innovative features. 

Early History of PHP 

Rasmus Lerdorf developed PHP in 1994 but to maintain his personal homepage. Later on, in 1998, Andi Gutmans and Zeev Suraski, two talented programmers, met him to take PHP to another level. So, the goal was to be used to redesign web pages.

Lerdorf named it Personal Home Page because he meant to use it personally. But his creation started to gain recognition by other programmers, and eventually, it turned into a global web programming language. Thus its name became Hypertext Preprocessor.

For sure, the aim behind the development of this language was not to gain such popularity and global usage. The interest was so uncontrollable and unexpected that Rasmus Lerdorf was not able to protect and limit its individuality.

Still, his venture has proved to be helpful for the coming generation with discovering new ways of web development.

History of PHP versions

It is easy to notice the growth of web development through the regular supplement of newer PHP extensions.

With every one of them, they allow web programmers to create more attractive and dynamic web pages. As time progressed, a lot of changes to PHP versions were made. 

  • PHP 1 and 2: The first two original variants of PHP are not created with enough features. However, they have established the benchmark for future versions to get additional advancement.
  • PHP 3 and 4: These two variants experienced significant developments as Zeev Suraski, and Andi Gutmans recreated the whole language. As a result, the new name of the language became Hypertext Preprocessor. During this period was added also improved parsing system named Zend Engine. The functionality is expanded and more powerful with introducing global, command-line interface and object-oriented programming.
  • PHP 5: In 2004 came the fifth variant of PHP, which was powered by the new Zend Engine II. The great new added feature of the latest version was the possibility to manipulate the database easily and have continuity. Moreover, in this version was added a binding variable.
  • PHP 6: In this version was embedded the ICU (International Components for Unicode) library into the program. However, this variant was abandoned, and it wasn’t launched in the market due to some other reasons.
  • PHP 7: In this version of the PHP programming language can be found various features. They didn’t exist in the earlier variants. Some of them are 64-bit integer support, return and scalar type declarations, etc. Also, it is powered by Zend Engine 3.

The latest release

The major version update is PHP 8.0. It brings various new features to the type system, error handling, object-oriented programming, strings, and more.

The future of a programming language that powers a vital part of applications and Internet websites results from many people’s efforts.

Although, PHP is trying to be conservative and exclude changes that might break a larger part of the applications. Still, the new release comes with numerous significant new features. Some of them are JIT, Named Parameters, Constructor Properties, and Attributes. They bring a lot of improvements and changes in syntax. Also, there are several minor changes, such as a resource to object migrations, advanced error handling, and modifications in operators and engine comparisons. They help to reduce the chances of overlooked bugs.