| aharvey | No | 2013-12-19 17:21 |
| ajf | Yes, right associative | 2013-12-28 00:32 |
| auroraeosrose | Yes, right associative | 2013-12-21 17:30 |
| bmajdak | No | 2013-12-20 21:14 |
| bwoebi | Yes, non associative | 2013-12-21 14:47 |
| chobieeee | Yes, right associative | 2013-12-22 06:08 |
| cyberspice | Yes, right associative | 2013-12-22 20:54 |
| datibbaw | Yes, right associative | 2013-12-19 08:10 |
| daverandom | Yes, right associative | 2013-12-19 13:55 |
| davey | Yes, right associative | 2014-01-03 03:34 |
| derick | Yes, right associative | 2013-12-19 10:43 |
| dm | Yes, right associative | 2013-12-20 14:20 |
| googleguy | Yes, right associative | 2013-12-20 00:28 |
| guilhermeblanco | No | 2013-12-21 19:38 |
| kassner | Yes, right associative | 2013-12-29 01:13 |
| krakjoe | Yes, right associative | 2013-12-21 14:40 |
| kriscraig | No | 2013-12-19 08:18 |
| levim | Yes, right associative | 2013-12-23 17:17 |
| lstrojny | Yes, right associative | 2014-01-05 13:12 |
| mbeccati | Yes, right associative | 2013-12-19 14:34 |
| mfonda | No | 2013-12-19 18:35 |
| nikic | No | 2013-12-19 11:21 |
| peehaa | No | 2013-12-26 23:52 |
| philstu | Yes, right associative | 2013-12-27 14:20 |
| pollita | Yes, right associative | 2013-12-22 20:32 |
| rasmus | Yes, right associative | 2013-12-21 14:54 |
| rdlowrey | Yes, right associative | 2013-12-21 14:51 |
| salathe | Yes, right associative | 2013-12-20 14:28 |
| seld | Yes, right associative | 2013-12-19 14:27 |
| stas | No | 2013-12-19 23:11 |
| uw | No | 2013-12-19 10:32 |
| willfitch | Yes, right associative | 2013-12-20 01:28 |
Copied from wiki.php.net, last synchronized Oct 13, 2026 11:51 UTC
This proposal is two-fold:
**.
**=A short working example:
echo 2 ** 3; // 8
It supports GMP overloading:
$base = gmp_init(2);
$exponent = 3;
var_dump($base ** $exponent);
// output
object(GMP)#3 (1) {
["num"]=>
string(1) "8"
}
Example of exponent assignment:
$x = 2;
$x **= 3;
echo $x; // 8
Important
The proposed associativity is right, just like how power towers work.
The operator precedence is:
Examples:
echo 2 ** 3 ** 2; // 512 (not 64)
echo -3 ** 2; // -9 (not 9)
echo 1 - 3 ** 2; // -8
echo ~3 ** 2; // -10 (not 16)
21-Dec-2013:
22-Dec-2013:
Should
-3 ** 2evaluate to9instead of-9?
According to the following resources, the scale tips more towards having the exponent precede the unary minus:
Similar languages
Dissimilar languages
Should
2 ** 3 ** 2yield64(left associative),512(right associative) or throw an error (non associative)?
The exponent operator evaluation order should be based on Tetration and therefore be right associative.
Languages with left associative exponential operator
** Languages with right associative exponential operator**
Languages with non associative exponential operator
Sources
PHP 5.6
The opcode ZEND_POW <165> and ZEND_ASSIGN_POW <166> is added.
External extensions such as vld or phpdbg would have to be updated, but I'm not aware of any core extensions that would otherwise be affected.
Voting will be based on the following:
** and **=,ZEND_POW and ZEND_ASSIGN_POW opcodes.Changes from 0.1:
** operator. See also: Discussion. This counts as an inclusion vote.A two third majority is required for acceptance.
Vote: Should PHP get a power operator in 5.6? — Yes, right associative: 22 · Yes, non associative: 1 · No: 9 (closed)
Voting ends on 5th of January 2014.
Power operator PR: https://github.com/php/php-src/pull/543