diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-01-15 17:04:24 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-01-22 11:12:04 +0100 |
commit | a50198d0fef652ca052cda642d6e98a9101eb73f (patch) | |
tree | 8bd51746c7418ae0826d527eb57fbebdb67b05d7 /Zend/tests/assign_coalesce_005.phpt | |
parent | 50ddff94b9989342e66678c311b3abf4e7d5a074 (diff) | |
download | php-git-a50198d0fef652ca052cda642d6e98a9101eb73f.tar.gz |
Implement ??= operator
RFC: https://wiki.php.net/rfc/null_coalesce_equal_operator
$a ??= $b is $a ?? ($a = $b), with the difference that $a is only
evaluated once, to the degree that this is possible. In particular
in $a[foo()] ?? $b function foo() is only ever called once.
However, the variable access themselves will be reevaluated.
Diffstat (limited to 'Zend/tests/assign_coalesce_005.phpt')
-rw-r--r-- | Zend/tests/assign_coalesce_005.phpt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Zend/tests/assign_coalesce_005.phpt b/Zend/tests/assign_coalesce_005.phpt new file mode 100644 index 0000000000..20510105e1 --- /dev/null +++ b/Zend/tests/assign_coalesce_005.phpt @@ -0,0 +1,14 @@ +--TEST-- +Coalesce assign (??=): Cannot reassign $this +--FILE-- +<?php + +class Test { + public function foobar() { + $this ??= 123; + } +} + +?> +--EXPECTF-- +Fatal error: Cannot re-assign $this in %s on line %d |