P++ Proposal: What Developers Need to Know

P++ Proposal: What Developers Need to Know

In this article we have a look at the proposal for a new, stricter dialect of PHP called P++, and how it could affect you as a developer if it succeeds in becoming a reality.

The proposal for P++ was put forward by Zeev Suraski, Co-Founder and CTO of Zend Technologies and lead contributor to PHP since 1997. In an internals mailing list, Suraski writes about several advantages to having a new dialect of PHP, including the ability to make changes to the language quickly without breaking existing code, and removing elements that are outdated.

In P++ ... we'd be able to get rid of elements that have little going for them other than backwards compatibility - such as short tagsZeev Suraski

What are the advantages of P++?

The main rationale behind the idea of the introduction of P++ lies in its ability to be a version of PHP that can be improved upon at a fast rate, with greater flexibility with regards to backwards compatibility. It would be opt-in and P++ and regular PHP would be able to co-exist in one project. It is still being discussed how exactly a developer would designate a file as P++; it has been suggested that the header tag <?p++ may be a solution.

Another major advantage is that P++ could be made into a stricter version of PHP. PHP's dynamic nature has been seen both as a strength and a weakness by developers since its inception, and it is hard to please everyone; P++ would solve the issue of whether PHP should be made into a stricter language.

One further advantage is that P++ would be very similar to PHP, at least initially. This means that it would be an easy language to pick up for the average PHP developer, and wouldn't require much study to get started with or integrate into new or existing projects.

What are the disadvantages of P++?

The suggestion of introducing P++ has been met with varied support. There are several disadvantages of having another dialect of PHP. First of all, there is the element of confusion that may arise if both PHP and P++ code are used within the same project. How will one know on sight whether a code block is PHP or P++ if the languages are so similar to each other?

It may be difficult for PHP code to be converted to P++, which is a downside if a developer wants to port their entire project to P++. In this circumstance, a developer would either have to rewrite their codebase in P++ (which may take some time) or combine PHP and P++ within their project, which may be undesirable.

Code tool support for P++ may take some time to emerge. Most, if not all of the popular coding tools such as PHPStorm support PHP out of the box, but the language has had a 25 year head-start. Introducing P++ would mean that code tool vendors would have to adjust their software to support the language; they make take some time to do this, especially if P++ isn't immediately popular with the PHP community.

In his article about why P++ is a bad idea, Benjamin Eberlei points out that documentation would likely be an issue if P++ was introduced. The PHP website would have to distinguish between regular PHP code and P++ and additions to core documentation would be required. In the intervening time before such documentation is added, what would P++ developers do if they need some assistance?

How would P++ work under-the-hood?

A designation that a file or method is written in P++ would most likely set the compiler into a special state. The file or method would then be processed differently to standard PHP. Developers would likely be able to write P++ code both in stand-alone files, or alongside regular PHP.

How will it affect me as a developer if P++ is introduced?

If you're a non-PHP developer, you will likely not be affected at all if P++ is introduced. Having said that, you may like to switch to PHP or P++ as a result of the introduction of the dialect.

If you're a PHP developer, on the other hand, the introduction of P++ would mean that you have an alternative dialect to PHP that you could use in your future projects. If you've been unhappy with PHP's dynamic nature, you could find that a stricter language such as P++ may be just what you need. There is no requirement to use P++, however; you could just stick to plain old-style PHP if that is what suits.

Update (17th August 2019)

P++ was voted against in the RFC.