In which year PHP 7 came out. Announcement of scalar types

Is it worth moving to a new version of PHP 7.0? - Definitely stands, do not even think - go!

In the seventh version there are quite a lot of innovations. The main ones are:

  • pHPNG kernel is based on PHPNG. The new kernel gives an increase in productivity sites from 40%;
  • type Hints and Return Values. Now, when declaring a function for each variable, you can specify your type, as well as the type of data that will return the function. Available types: INT, Float, String and Bool;
  • combined comparison operator and much more.

Some extensions were removed in PHP 7:

  • mysql

Already in PHP 5.6.x, the use of these extensions was undesirable. Instead of "MySQL", use "PDO", and instead of Ereg → Preg.

You can get acquainted in more detail with PHP 7 novelties on the official page.

Should I go to PHP 7?

On the this moment The simplest thing you can do to increase the performance of the site is to go to PHP 7.0.x. The speed gain also depends on how your project is written. If you still doubt, show some comparisons:

Benchmark PHP 5.6 VS PHP 7 For necto frameworks (Zend Framework, Magento, Drupal, MediaWiki, Wordpress, Laravel, Sugarcrm, etc.):

For all frameworks, productivity growth is significant. Let's see what is the case with the functions and designs of the kernel:

Benchmark PHP 5.6 VS PHP 7 For the functions and designs of the kernel:

If the graphs convinced you, you can try to transfer your site to the new version of PHP and experience the increase in the real project.

Colleagues with ElasticWeb said that before starting a new server with PHP 7, they launched a large state project working on Laravel 5. It was a kind of performance test. new version PHP and server as a whole. Previously, this project was on the server with PHP 5.6. After transferring the site, the page began to be opened much faster, while the use of resources has been halved.

To prepare the move to PHP 7, they used PHP 7 Migration Assistant Report (MAR). Most of the popular CMS / Framework already have compatibility with PHP 7, so the main task has been reduced to testing Custom plugins.

WordPress 4, Drupal 8/7 and latest version Joomla is ready for PHP 7!

Hello!

December 3 was a PHP 7 release. We were transferred for you a description of new products from the documentation page http://php.net/manual/en/migration70.new-features.php. This is the first part.

Announcement of scalar types

Now two types conversion modes are used: implicit conversion (COERCIVE) and explicit (STRICT).

Types are available for parameters:

  • strings (String),
  • integers (int),
  • floating communion (float),
  • boolean variables (BOOL).

This complements the data type set in PHP 5: class names, interfaces, arrays (array) and Callible.

Result:

To enable strict typing mode, use the Declare directive at the beginning of the file:

Declare (strict_types \u003d 1)

Typization mode applies to a specific file. Enabling strict typing affects the output of scalar values, return values, embedded PHP functions and extension functions.

Definition of types of returned values

In PHP 7, it became possible to declare the type of return value. This directly correlates with a new typing mode: with strict typing, the return values \u200b\u200bmust strictly match the specified type, otherwise the exception will be discarded Typeerror..

A set of types of returned values \u200b\u200bis the same as for arguments.

Result:

Array (\u003d\u003e 6 \u003d\u003e 15 \u003d\u003e 24)

Unification operator with NULL value

The unification operator with NULL (??) is entered to improve the readability of the code in the case when the ternary operator and isset () is usually used. The operator returns the first operand if the argument is defined and is not equal to NULL and the second operand in any other cases.

Operator "Spaceship"

Compare two expressions, returning -1, 0 and 1, when the first argument is less, equal to or more of the second, respectively. Comparison is made using the usual comparison rules of PHP types.

one; // 0 ECHO 1<=> 2; // -1 echo 2<=> one; // 1 // Floating Point (Float) ECHO 1.5<=> 1.5; // 0 ECHO 1.5<=> 2.5; // -1 ECHO 2.5<=> 1.5; // 1 // Rows Echo "A"<=> "a"; // 0 ECHO "A"<=> "B"; // -1 echo "b"<=> "a"; // 1?\u003e

Definition of constant arrays Define ()

Constant arrays can be declared using define (). In PHP 5.6, they could only be defined using the Const directive.

Anonymous classes

Support for announcement of anonymous classes with nEW CLASS.. This can be used to decorate disposable objects without writing a whole class.

logger; ) Public Function Setlogger (Logger $ Logger) ($ this-\u003e logger \u003d $ logger;)) $ App \u003d New Application; $ App-\u003e SETLOGGER (Public Function Log (String $ MSG) (Echo $ MSG)); VAR_DUMP ($ App-\u003e getLogger ()); ?\u003e

Result:

Object ( [Email Protected])#2 (0) {}

Unicode Symbols Escape

Unicode symbols are set by hexadecimal code in a double-quotes or Herdoc-definition string. Adding one or more digits "0" before the symbol code is allowed.

Echo "\\ U (AA)"; Echo "\\ U (0000AA)"; Echo "\\ U (9999)";

Result:

ª ª // SAME AS BEFORE BUT WITH OPTIONAL LEADING 0 "S 香

Closure :: Call ()

Closure method :: Call () is a more productive way to temporarily bind the context of the object to closure and its call.

x;); $ getx \u003d $ getxcb-\u003e bindto (new a, "a"); // Intermediate closure of Echo $ GETX (); // PHP 7+ $ GETX \u003d FUNCTION () (RETURN $ THIS-\u003e X;); Echo $ GetX-\u003e Call (New A);

Result:

The rest of the innovations are in the second part. Stay Tuned.

Go to PHP 7.0 or wait? So we thought so long, weighed, pretended. However, yesterday came the moment when it was necessary to quickly make a decision

It happened that anyone's master master, no sysadmin Hyloada, does not want. The portal began to slow down from the load. Coming visitors who have paid access to closed materials and simply visitors who are simultaneously mailing 100k + to the portal subscribers, HelpDeske is not able to work adequately with admin and provide assistance to people

As a result, the evening was performed with PHP 5.6 on PHP 7.0

Brief characteristics of the server

  • OS: FreeBSD.
  • RAM: 5GB
  • CPU: Xeon E5335 2.00GHz * 4 (kernels)

Since it is FreeBSD and keep at the same time more than one PHP version is not possible (in fact, it is possible, but it will have to get it up), Downym was only 40 minutes that took the demolition of PHP 5.6 and install PHP 7.0

By the way, we still have a server on Gentoo, which provides an opportunity. Currently there PHP 5.6, 7.0, 7.1. But this is to the word

And that's what we did. Let's look at day charts where yesterday's day, and on the right today

What has not changed

What changed

What we collided with difficulties

  • In the current PHP 7.0 there is no MEMCACHE module. I had to download third-party port
  • No module MySQL. To this you need to be ready and in advance to foresee the transition plan to MYSQLI. More or less modern frameworks support MySqli
  • If you are using PECL-PDFLIB, you will be ready for what it will not work. We use wkhtmltopdf.
  • Part of the portal used MPDF. It does not work with PHP 7.0. Installed fresh with Composer
  • Conducted a light refactoring code

Output

With the same number of portal visitors, the load on the server fell twice

Alexander Black

system Administrator

According to some studies, about 80% of all sites are written on it. And it is not all strange, because even such network giants as In contact with and Facebookwere created with the help of it. About popularity can also be judged because the request "" is requested in search engines much more often than other languages. So one request hosting Perl. Greets 150 – The aforementioned hosting PHP.

The language was created in 1994 and was originally a set of scripts. Over time, the scripts were redone to the interpreter on S.

The main features and features of the PHP language:

  • ability to work with various web servers ( IIS.);
  • ease of learning and flexibility in work;
  • support for Databases - , MSSQL, Oracle, Postgre, Mongodb and others;
  • for popular OS there are appropriate PHP packages, Ie you can create sites on;
  • compatibility with most hosting servicesprovided by providers. You can easily place the site written on PHP on any hosting. How to secure PHP on the server? Our advice.
  • php does not stand still and constantly develops, which attracts developers from around the world.

What kind version PHP. Are relevant at the moment?

By right, it is considered relevant versions of PHP 4 and 5. Version 4 has its own popularity and is used to write various web applications. PHP 5 has many additional features, but in turn, not fully compatible with the fourth version of the language. therefore some programs (written in PHP 4) will not be able to work in the PHP 5 environment. As additional tools to the tongue of the language are often used modules. For example, special modules have been developed for work with graphics, or modules that implement interactions with different databases.

After entering the 5th version of the language, everyone expected the sixth. But PHP 6 was never able to implement himself, due to problems with UNICOD support, so in 2010 the development and implementation of this version were discontinued.

PHP 7 is a new version with new features.

Not so long ago, December 3, 2015, a new release of a popular programming language has been released -PHP 7.0.0 That gave the development of the PHP 7 series. The language has already managed to conquer its fans for the twenty-year-old history of existence. The scripting language of general purpose is used to create various web applications, including writing paid and free CMS. For example, Joomla !, Drupal, WordPress and TP.

Further talk about new PHP 7 features And we'll figure it out why the developers waited for him so much. After all, despite the frequent criticism of this language, most hosting providers support it, including the latest PHP versions. The language is the most demanded on the use criteria. The new version is essentially experimental and based on PHPNG (next PHP generation), the principle of increasing productivity is based on a reduction in memory consumption.

PHP 7 language is designed with the addition of the new version of Zend Engine. If you compare it with the previous version of 5.6 (the new release of which appeared in November of the same year), then the web developers of the language primarily note the improved performance of the new technology: PHP 7 doubles the predecessor's chunk.

Consider the items,what the new version of PHP offers :

  • full support 64-bit systems;
  • memory use is much reduced;
  • added the functionality of the abstract syntax;
  • most fatal errors are transformed into exceptions;
  • improved exception hierarchy;
  • random generator numbers became safer;
  • anonymous classes;
  • removed outdated sapis SAPI / AOLSERVER, SAPI / Apache SAPI / Apache_Hooks, SAPI / Apache2Filter, SAPI / CAUDIUM, SAPI / CONTINUITY, SAPI / ISAPI, SAPI / MILTER, SAPI / NSAPI, SAPI / PHTTPD, SAPI / PI3WEB, SAPI / ROXEN, SAPI / THTTPD, SAPI / TUX, SAPI / WebJames, Ext / MSSQL and EXT / Sybase_ct);
  • stop supporting designer in the style of PHP 4, in which the name of the constructor coincides with the class name;
  • created method Closure :: Call ();
  • in addition OpenSSL there is support TLS extension ALPN (Application-Layer Protocol Negotiation) To match the application level protocols that are used to ensure a secure connection. Applied in SPDY and HTTP / 2;
  • a union operator with NULL ?? ;
  • providing a grouping of definitions in the USE statement (for example, Use DoctrineCommonCollectionSEXPR (COMPARISON, VALUE, COMPOSIEXPRESSION);) and much more.

Download and familiarize yourself with all the advantages of the new PHP version on official pageAlso there you can download migration guide. New Release - not just the next version of PHP, and the beginning of the development of a new way in programming languages. To launch it, it took two years of zealous developments, which helped create an improved product.

If you are looking for reliable 7th version , Contact us to the company Hyper Host.our virtual hosting servers support PHP 7. We hope new opportunities will come to your taste. We, in turn, will be happy to help!

7435 times 1 today viewed once (a)

PHP is a programming language that is mainly used in web development, as a rule, in the back-end part. PHP has a sufficiently long history - his first version appeared more than 20 years ago, in 1995. During this time, 7 PHP versions were issued, the last of which appeared in December 2015. About her and will be discussed in this article.

The release of PHP 7.0 became a breakthrough, as it was based on the phpng - experimental and actively developing PHP project, the name of which is decrypted as "PHP Next Generation" - "The next generation PHP". This technology could be used in previous PHP versions, however, it was in PHP 7, it was introduced as a fundamental. When it is developed, the goal was set to increase the performance of PHP, but not losing compatibility.

Zend Engine.

PHP 7 is based on the third version of the Zend Engine in which the PHPNG project was developed.

Innovations

First of all, the innovations in PHP 7 have affected the most important parameter applications - this performance and memory consumption.

The main change in which is primarily mentioned in the conversation about PHP 7, this performance improvement: PHP 7 indicators are approximated to HHVM indicators (developed by Facebook system, which allows you to speed up the PHP code transformation several times). Not the last reason for this was the fact that the co-founder of Zend Technologies (PHP kernel companies) Zeev Suraski considers HHVM as one of Zend's competitors. And the leading developer of PHP 7 Zend Technologies company and PHPNG author Dmitry Stans assures that the difference in the performance of PHP 5.0 and PHP 7 on the synthetic test bench.php is 14 times. In practice, most users are inclined to believe that PHP 7 is about two times faster than the previous version.

HHVM uses the so-called JIT (Just-In-Time) compilation for the code conversion - despite the fact that the JIT in the 7 PHP version did not appear, PHP 7 supports a better migration, which allows you to improve performance at times. It is a new level of productivity Dmitry Stack highlights as the main feature of PHP 7.

Performance Improvement managed to achieve and thanks to the fact that the compiler now generates a more spectacular and short byte code.

Nowadays, it is extremely important to think about users not only in stationary, but also mobile devices, so the developers of PHP 7 have improved engine performance and reduced memory consumption, and also added the ability to use a native local storage. In addition, PHP 7 allows you to perform asynchronous tasks.

By the way, the development took into account the popular trends in reducing the consumption of resources of the planet, so PHP 7 has ability to handle more trafficUsing all the same server resources.

New features

In PHP 7 there are many new features, each of which makes the development of more comfortable and simple. Next you can get acquainted with some of them.

  • Two new exceptions (Exception and Error) - if in previous PHP versions it was impossible to handle fatal errors, then in a new release, the action leading to this emit exceptions, that is, the completion of the script will not happen.
  • Anonymous classes - Now PHP 7 supports this type of classes, which is often used in C ++ and Java to perform callback functions. These classes are mainly used to create simple items:

setLogger (New Logger ()); // PHP 7+ Code $ Util-\u003e Setlogger (NEW Class ($ MSG) (Echo $ MSG;)));

Anonymous classes can be invested, but they will not be available protected or private properties of the external class.

  • Ability to indicate scalar types (SCALAR TYPE HINTS) - In previous versions, it was possible to indicate the type of values \u200b\u200breceived; Now you can also indicate scalar types:

Rows (`String`), whole (` int`), numbers (`Float`), boulders (` bool`).

This innovation is aimed at facilitating the writing of the code and improve its readability. But the use of these values \u200b\u200bas the names of the classes is categorically prohibited, because This can lead to critical errors.

  • Abbreviated USE design - the opportunity appeared in PHP 7 combine the declaration of USE groupsthat will undoubtedly be positively affected both at speeds and at the perception of code:
  • New operators NULL COALESCING OPERATOR (??) and Combined Comparison Operator. (<=>Also, he is known as Spaceship Operator) - these two new operators, which some refer to syntactic sugar help write a more concise and understandable code.

NULL COALESCING OPERATOR is an union operator that checks whether the variable exists and returns its value (or default value):

$ Action \u003d $ _post ["action"] ?? "index";

Combined COMPARISON OPERATOR is a comparison operator that is useful for use in Callback functions for USORT (). It compares two values \u200b\u200band, depending on the result, returns -1, 0 or 1:

FUNCTION ORDER_FUNC ($ A, $ B) (Return $ A<=> $ B; )

The priority of this operation is equal to the priorities of other comparison operations, and it cannot be associated with the previous challenge, because This is a non-abassociative operator.

  • Function ASSERT ()- in PHP 7, this function is processed in a special way to exclude overhead; You can use it for debugging, and further disable.
  • Filtration unservialize () - This innovation will ensure the safety of serialization of objects. The developer will be able to determine which classes should be treated, and which are not.
  • Representation integers in the form of 64-bit In PHP 7 for Windows X64: now PHP supports strings longer than 231 bytes in 64-bit assemblies.
  • Delegation of generators - with help The complex generator can be divided into several smaller. Like some other innovations, this innovation is aimed at writing a cleaner and convenient code for reuse.
  • The appearance of a new class Intlchar. - It increases the library feature set to localize the International Components for Unicode applications and has a class methods and a confontant to work with Unicode.
  • The ability to define arrays as constant values \u200b\u200bthat are declared via define ().
  • The ability to assign reserved keywords to the names of methods.
  • The emergence of a new identifier of simple PHP_INT_MIN values.

As for the old functions, the part of the most unclaimed features was excluded: for example, ASP and Script tags were removed, as well as regular expressions compatible with POSIX, and extension EXT / MYSQL.

PHP and web servers

PHP is widely used when writing a variety of web applications, because This language is compatible with various web servers (Apache, Nginx, IIS), databases (MYSQL, Postgre, MongoDB, etc.), as well as operating systems.
Therefore, traditionally innovations were touched by not only the language as a whole, but also those of his parties that are associated with hosting.

First of all, PHP 7 was introduced Abstract Syntax Tree (AST) - an abstract syntax tree, which is an intermediate link in the compilation process. It is on this model that a syntax analyzer is now founded. Thanks to this, you can now create a more productive operating code.

Another innovation is Uniform Variable Syntax - Universal syntax for variables. This allows, on the one hand, to solve some of the inconsistencies that are associated with the calculation of variable values, but, on the other hand, it creates the need to rewrite some rarely used parts of the code.

Let us return once again to an increase in PHP 7 performance: it is favorable to reflect on the functionality of all hosting, because they will be able to increase the number of their users without increasing the number of servers or other improvements.

One of the reasons for improving performance is optimization of the structure of the internal dataWhat greatly improved the process of working with memory.

It is impossible not to say about some backward compatibility issues that may occur when switching to PHP 7. For example, it is not possible to use several default expressions in Switch, because Otherwise, you will see a mistake. However, in general, these problems are insignificant against the background of those new features that PHP 7 offers.

Output

PHP 7 release is not just the release of the new PHP version, but a certain starting point for the following php versions of the new generation. The results of a multitude of PHP 7 innovations became a cleaner, convenient and understandable code, significantly increased productivity and much more that you can independently evaluate by updating the virtual server to the seventh version of PHP.