Development
What's coming in PHP 7.0
Version 7.0 of the PHP language and its interpreter are scheduled to be released December 3, following a series of eight release-candidate (RC) builds. This release will represent a major upgrade of PHP that adds several new language features and fixes some longstanding issues. In addition, the new release is said to be substantially faster, which should be a boon to those running PHP sites even if they do not choose to take advantage of changes to the language.
Operators and functions
The combined-comparison (or "spaceship") operator is a new three-way logic operator that can be used to compare two arbitrary PHP expressions and that will evaluate to one of three values (one, zero, or negative one). It takes the form <=> (much like its equivalents in Perl and Ruby). The comparison a <=> b evaluates to zero if a = b, to one if a > b, and to negative one if a < b. This new operator is, ultimately, syntactic sugar; the same tests could be expressed in somewhat more verbose form using the existing comparison operators. But it is an oft-requested feature that many developers expect due to its availability in other languages.
A second new operator is "??"—the null coalescing operator. The operator takes two operands and returns the first if it exists and it is not NULL; otherwise, the second is returned. For example:
$username = $_GET['user'] ?? 'nobody';
will set username to either the user HTTP request parameter or to 'nobody'. Here again, the operator primarily provides a convenience function to spare developers from performing a test to see if the user parameter is NULL in addition to performing the lookup.
There is also a new integer-division function, intdiv(). Many other languages have supported integer division for a long time, but it is new to PHP. The function spares developers from having to implement their own workarounds. In addition, the assert() function has been extended to support expectations. This allows the developer to optionally add a custom exception as the second argument to an assertion. The intended use case is that assertions can be placed in code during development that will trigger exceptions useful to the programmer, but that those assertions and exceptions will be removed from production code.
Data types
In PHP 7, it is possible to declare the return type of a function. This feature has been proposed on multiple occasions in the past; the proposal that finally succeeded did so by managing to not break backward compatibility: it does not introduce new types or keywords, nor does it modify any existing keywords. The syntax is relatively simple; a function declaration indicates its return type after the parameter list but before the code block begins:
function foo(): int { return 42; }
Function definitions are not required to declare their return type, except in cases where a method inherits from a parent method that does declare its return type.
PHP 7 adds type declarations for four scalar types: int, float, string, and bool. These types are available for use both as return-type declarations and as argument type hints:
function add(int $a, int $b): int { return $a + $b; }
The feature had been requested before, but an implementation was held up as the project debated whether adding it would necessitate a adding strict type checking as well. The solution adopted attempts to strike a middle ground. By default, the interpreter uses weak type checking, but developers can enable strict type checking on a per-file basis with a declaration at the start of the file:
declare(strict_types=1);
Developers can also now define array constants with the define() function:
define('ANIMALS', [ 'dog', 'cat', 'fruitbat' ]);
In earlier releases, array constants could only be defined with the const keyword, which limited them to being declared at the top-level scope. Using define() enables programmers to define array constants inside functions, loops, or other blocks.
Also new is support for anonymous classes, using the syntax:
new class (arguments) {definition}
This allows developers to create "disposable" classes that are thrown away as soon as they are no longer in use. It is akin to anonymous functions, which PHP added support for in the 5.3 release, back in 2009.
Other changes
The new release also fixes the inconsistency in how various platforms (specifically, those using different 64-bit data models) handle strings and integers. Previously, PHP used long to represent signed integers and int to handle string lengths. Unfortunately, those data types are of different sizes on Windows, SPARC64 systems, and non-SPARC64 Linux; this caused considerable trouble for developers wanting to write portable PHP code. The new release now uses data types that are guaranteed to be 64-bit on all 64-bit platforms.
Throwable exceptions are now supported, replacing many fatal errors from earlier releases.
Removing dead and deprecated code is often a welcome change, and the PHP 7 release removes functionality that was declared deprecated in the 5.x series. Furthermore, a long list of abandoned or unsupported extensions and Server Application Programming Interfaces (SAPIs) have also been removed. The SAPIs removed include connectors to AOL, Apache 1.x, Microsoft IIS, and the Tux web server.
For existing site users, perhaps the most noticeable change is that PHP 7 is reportedly up to twice as fast as PHP 5.6. This speed improvement comes from the refactoring of the core PHP interpreter that was previously known as "phpng." The 7.0 release merges in the new core, dropping the "-ng" suffix from its moniker.
Speed-ups are notoriously hard to generalize, but hosting provider Engine Yard
reports that PHP 7 is on par with the PHP just-in-time compiler used
by Facebook. The Zend web site offers one
noteworthy data point, claiming that "when PHPNG was published,
the WordPress homepage required approx. 9.4 billion CPU instructions
to execute. As of now – it requires only 2.6 billion
".
The last stable PHP release, version 5.6, debuted a bit over one year ago, in August 2014. The 6.0 major-version number was skipped entirely, since that branch got bogged down in a controversial shift to Unicode for all string handling. The new release does add a Unicode escape character, \u, but does not incorporate the massive changes once planned for PHP 6. Considering how divisive that process was, it is a good sign that the 7.0 release has finally seen the light of day, and seems to provide the functionality that many of its fans have been asking for.
Brief items
Quotes of the week(s)
Pitivi 0.95 released
The Pitivi 0.95 release is out, bringing a lot of changes to this longstanding video editor project. "This one packs a lot of bugfixes and architectural work to further stabilize the GES backend. In this blog post, I’ll give you an overview of the new and interesting stuff this release brings, coming out from a year of hard work. It’s pretty epic and you’re in for a few surprises, so I suggest listening to this song while you’re reading this blog post."
KiCad 4.0 available
Version 4.0 of the electronic design automation (EDA) tool KiCad has been released. Highlights include a new rendering backend, new formats for saving printed circuit board (PCB) designs and object footprints, and tunable interactive trace routing.
Enlightenment DR 0.20.0 released
Version 0.20 of the Enlightenment framework has been released. Most notable is the addition of Wayland support; other changes include a geolocation module and a new screen-management infrastructure.
wayland-protocols 1.0 available
The 1.0 release of wayland-protocols, the package of extensions and complementary protocols for use with the core Wayland protocol, is now available. All of these ancillary protocols are considered unstable at the present time; they include extensions for full-screen shells, input methods, pointer gestures, and more.
Free Pascal 3.0.0 released
Version 3.0 of the Free Pascal Compiler has been released. There is an extensive list of changes at the project site; some of those include codepage-aware strings and an integrated Pascal source repository.
Django 1.9 released
Django version 1.9 is now available. New in this release is support for password validation, running tests in parallel, and an on_commit() hook for performing actions after a transaction has been successfully committed.
Poettering: Introducing sd-event
Lennart Poettering introduces the sd-event API for the implementation of event loops. "sd-event.h, of course, is not the first event loop API around, and it doesn't implement any really novel concepts. When we started working on it we tried to do our homework, and checked the various existing event loop APIs, maybe looking for candidates to adopt instead of doing our own, and to learn about the strengths and weaknesses of the various implementations existing. Ultimately, we found no implementation that could deliver what we needed, or where it would be easy to add the missing bits: as usual in the systemd project, we wanted something that allows us access to all the Linux-specific bits, instead of limiting itself to the least common denominator of UNIX."
Thunderbird to be separated from Mozilla
Mozilla leader Mitchell Baker has announced that the Thunderbird email client project will, eventually, be spun out of Mozilla. "Therefore I believe Thunderbird should would thrive best by separating itself from reliance on Mozilla development systems and in some cases, Mozilla technology. The current setting isn’t stable, and we should start actively looking into how we can transition in an orderly way to a future where Thunderbird and Firefox are un-coupled."
Newsletters and articles
Development newsletters from the past week(s)
- What's cooking in git.git (November 20)
- What's cooking in git.git (November 24)
- What's cooking in git.git (December 1)
- GNU Toolchain Update (October/November)
- LLVM Weekly (November 23)
- LLVM Weekly (November 30; issue #100)
- OCaml Weekly News (November 24)
- OCaml Weekly News (December 1)
- Perl Weekly (November 23)
- Perl Weekly (November 30)
- PostgreSQL Weekly News (November 29)
- Python Weekly (November 19)
- Python Weekly (November 26)
- Ruby Weekly (November 19)
- Ruby Weekly (November 26)
- This Week in Rust (November 23)
- This Week in Rust (November 30)
- Tahoe-LAFS Weekly News (November 24)
- Tahoe-LAFS Weekly News (December 2)
- TUGboat (December)
- Wikimedia Tech News (November 23)
- Wikimedia Tech News (November 30)
Langridge: No UI is some UI
At his blog, Stuart Langridge takes
issue with a recent Medium
post by Tony Aubé titled No UI is the New UI. Aubé's
premise is that "invisible" applications—those that use
text-messaging or voice-recognition rather than on-screen
interfaces—are the future of UI design. Langridge, however,
contends that "until very recently, and honestly pretty much
still, a computer can’t understand the nuance of language. So 'use
language to control computers' meant 'learn the computer’s language',
not 'the computer learns yours'.
" More to the point,
"understanding you is laughably incomplete and is obviously the
core of the problem, although explaining one’s ideas and being
understood by people is also the core problem of civilisation and we
haven’t cracked that one yet either
". There is less reason to
be optimistic about language-based interfaces, he concludes: "I will say that point-and-grunt is not a very sophisticated way of communicating, but it may be all that technology can currently understand.
"
GIMP is 20 Years Old, What’s Next? (Libre Graphics World)
This Libre Graphics World article looks at the challenges faced by the 20-year-old GIMP project. "If you've been following GIMP's progress over recent years, you couldn't help yourself noticing the decreasing activity in terms of both commits (a rather lousy metric) and amount of participants (a more sensible one). 'GIMP is dying', say some. 'GIMP developers are slacking', say others. 'You've got to go for crowdfunding' is yet another popular notion. And no matter what, there's always a few whitebearded folks who would blame the team for not going with changes from the FilmGIMP branch. So what's actually going on and what's the outlook for the project?"
Gräßlin: Looking at the security of Plasma/Wayland
Martin Gräßlin looks at the security of the Plasma desktop running under Wayland; it's better than X11, but with some ground yet to cover. "Now imagine you want to write a key logger in a Plasma/Wayland world. How would you do it? I asked myself this question recently, thought about it, found a possible solution and had a key logger in less than 10 minutes: ouch."
Page editor: Nathan Willis
Next page:
Announcements>>