Up to this year, the only argument I could make regarding Eevee’s statement is that additionally, the bcmath and gmp extensions each offer a pow-style function. However, history has intervened, rendering his assessment as untrue, effective as of PHP5.6.

A member of the original PHP Group 12 years ago made the following pronouncement with respect to adding a pow operator:

“not going to happen. just suck it up and use pow()”

jimw@php.net, 2002 (see bugs.php.net/bug.php?id=13756)

Winstead’s prediction held true for years as Userland diligently followed his advice — until recently. Why? Maybe there was something in the air 🙂 During 2012 and 2013, I gave variations of a talk about PHP’s numeric quirks at CodeWorks, OCPHP Meetup, SCALE’s Birds of a Feather, and later at OSCON followed up by a talk for the Web and PHP Conference. In each presentation, I mentioned the peculiar situation of PHP lacking a pow operator and contrasted that deficit with what Python offers a developer, even tho’ my loyalties are with PHP.

All of a sudden in November 2013, Tjerk Meesters put forth an RFC proposing an exponent operator for PHP, consisting of the double asterisk (**) symbol which follows other languages, such as Python, Perl and Ruby. Did my campaign for an exponent operator have any bearing? Who knows? The most reasonable conclusion is that the time had simply come for this operator to make its debut in PHP.

When voting commenced, the outlook seemed to change hourly with victory seeming assured and then doubtful. We in Userland while mostly unable to vote, could at least urge all who were eligible to vote. Note, this particular RFC required a 2/3 majority for the proposal to pass. So, I respectfully asked via this post that *all* of those with voting privileges vote!

I hoped that shortly after the New Year arrived PHP would join the modern age and finally have an exponent operator! But some worried about whether this addition would ultimately benefit PHP and/or Userland, fearing that the new operator might lead to needless confusion. See discussion at Reddit. The concerns are valid and so I’d like to explore them. Here’s what you need to know:

** does not function identically as pow() in all cases. For that reason, you may prefer at times to continue using pow(). For example, consider the following:

If you wonder whether PHP really needs yet another operator, ask yourself, which code you would rather read/write:

<?php
echo pow(2,3); // 8
echo 2 ** 3; // 8

The latter involves a difference of only two fewer key strokes but its form is certainly much more legible and its meaning is immediately apparent.

Of all the RFC’s I’ve followed, this one progressed dramatically as my updates below indicate:

~~~~~~~~~~~~~~~~~

Update – Dec 22, 2013:
This vote is like a roller coaster. Meesters opted to close the vote and revise the RFC since the Father of PHP upon closer inspection noticed that it included a pow construct. The problem with that feature is that it would interfere with the perfectly good pow() which hardly requires replacement. So, it sure seemed that the RFC would revert to “Discussion” status with voting happening at some unspecified time in 2014. But, according to the RFC’s change log the voting is on again as of Dec 22nd. Well, that’s probably according to European time. Look at the vote again and see who is coming on board with this proposal. There is hope! Yay!

Update – January 6, 2014:
One of the core contributors wants to extend the deadline for voting, but the RFC’s author rejects that idea, noting that the voting period was three weeks long instead of the usual two. So, I’m happy to report that Meesters has stated that PHP is going to have a new exponent operator as of PHP5.6 (see http://markmail.org/message/7ny7z6zts6sca6tb). The vote was more than the required 2/3 majority.

~~~~~~~~~~~~~~~~~

At one point during the voting, I noticed that the individual votes suddenly disappeared, the only number visible being the total vote tally, a disconcerting situation which caused concern even among various core contributors. (Other active RFC’s were similarly effected.) This incident raises questions about what precisely happened and why as well as how such a situation enfolded — but that is the subject for another post. In the meantime, let’s celebrate that what some deemed as impossible miraculously became possible. The ** operator will appear in PHP (version 5.6). This seemingly small change will be a welcome addition, making it ever so much more pleasurable for users to work with exponents.