diff options
author | Dmitry Stogov <dmitry@zend.com> | 2015-02-12 13:57:12 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2015-02-12 13:57:12 +0300 |
commit | 97fe15db4356f8fa1b3b8eb9bb1baa8141376077 (patch) | |
tree | b0c6dcbe1d5444e758e71cf4802794d56550c940 /tests/lang/foreachLoop.013.phpt | |
parent | 741b5952c6d8b0a75c9b421e10b9bace5b7a89f4 (diff) | |
download | php-git-97fe15db4356f8fa1b3b8eb9bb1baa8141376077.tar.gz |
Fix "forech" statemt behaviour according to https://wiki.php.net/rfc/php7_foreach
Squashed commit of the following:
commit 1e41295097576dbce6c197ddb7507c07ccae3cbe
Author: Dmitry Stogov <dmitry@zend.com>
Date: Sat Jan 31 07:28:58 2015 +0300
Generalize HashTableIterator API to allows its usage without involvement of HashTable.nInternalPonter
commit 5406f21b11e563069d64045e599693b51c444b63
Author: Dmitry Stogov <dmitry@zend.com>
Date: Fri Jan 30 18:08:43 2015 +0300
Reduced alghorithms complexity
commit b37f1d58d2a141b6e1d980a461ccb588d4317d2e
Author: Dmitry Stogov <dmitry@zend.com>
Date: Fri Jan 30 18:08:30 2015 +0300
Fixed test name
commit fb2d079645829b12ed4e55a461034df6400bc430
Author: Dmitry Stogov <dmitry@zend.com>
Date: Fri Jan 30 18:08:05 2015 +0300
API cleanup
commit 08302c0d6d1cab279b9f2129df03a057baddf2ff
Author: Dmitry Stogov <dmitry@zend.com>
Date: Fri Jan 30 14:20:46 2015 +0300
Make array_splice() to preserve foreach hash position
commit cc4b7be41e2e2b9b0d7a3c8e98466b8886692e6e
Author: Dmitry Stogov <dmitry@zend.com>
Date: Fri Jan 30 12:24:31 2015 +0300
Make internal function, operation on array passed by reference, to preserve foreach hash position
commit 5aa9712b0a30303aadfe3bdd8ae1f072ca3e6ba1
Author: Dmitry Stogov <dmitry@zend.com>
Date: Fri Jan 30 09:49:35 2015 +0300
Implement consistent behavior for foreach by value over plain object
commit 4c5b385ff53ae9f0b52572e98c4db801f56603b0
Author: Dmitry Stogov <dmitry@zend.com>
Date: Fri Jan 30 07:56:37 2015 +0300
More careful iterators update.
commit 721fc9e80d2ee8f2cd79c8c3cdceffae2c72de92
Author: Dmitry Stogov <dmitry@zend.com>
Date: Thu Jan 29 21:43:28 2015 +0300
Added new test
commit 15a23b1218b3e38630d677751a975907daa2cd54
Author: Dmitry Stogov <dmitry@zend.com>
Date: Thu Jan 29 21:05:02 2015 +0300
Reimplement iteration magic with HashTableIterators (see https://wiki.php.net/rfc/php7_foreach#implementation_details)
commit 10a3260b1f16b6075fd8140f673dfef4d5efea91
Author: Dmitry Stogov <dmitry@zend.com>
Date: Thu Jan 29 21:04:44 2015 +0300
New test
commit eef80c583762d1e98d177cdbb27e3a8a6b0c4539
Author: Dmitry Stogov <dmitry@zend.com>
Date: Wed Jan 28 16:52:21 2015 +0300
Fixed foreach by reference iteration over constant array
commit 61e739187391661e2d541947bec25d7dcc4479f3
Author: Dmitry Stogov <dmitry@zend.com>
Date: Wed Jan 28 14:59:54 2015 +0300
Fixed temporary variable re-allocation pass
commit 92e90c09f085c22707ff4a59201f016f56e0ef8b
Author: Dmitry Stogov <dmitry@zend.com>
Date: Wed Jan 28 12:44:57 2015 +0300
Fixed operand destruction in case of exceptions in iterator
commit dd2a36a2074bbb0cb31de00b66dcf2812d6d753f
Author: Dmitry Stogov <dmitry@zend.com>
Date: Wed Jan 28 10:02:34 2015 +0300
Use GET_OP1_ZVAL_PTR_DEREF() (IS_TMP_VAR and IS_CONST can't be IS_REFERENCE)
commit 4638f7b91407c48710007af82a68da0007c820f2
Author: Dmitry Stogov <dmitry@zend.com>
Date: Wed Jan 28 07:43:28 2015 +0300
Change "foreach" statement behavior (this is just a PoC yet)
- "foreach by value" don't relay on internal array/object pointer and doesnt perform array duplication. It just locks it incrementing reference counter. If the original array is modified by some code, the copy on write is performed and "foreach" still work with the old copy.
- it makes no difference if array given to "foreach by value" is reference itself
- "foreach by reference" still use internal array/object pointer and should work similar to PHP-5. (This id not completely implemented)
Diffstat (limited to 'tests/lang/foreachLoop.013.phpt')
-rw-r--r-- | tests/lang/foreachLoop.013.phpt | 118 |
1 files changed, 48 insertions, 70 deletions
diff --git a/tests/lang/foreachLoop.013.phpt b/tests/lang/foreachLoop.013.phpt index b0c5e8dcf5..ea728156f0 100644 --- a/tests/lang/foreachLoop.013.phpt +++ b/tests/lang/foreachLoop.013.phpt @@ -1,7 +1,5 @@ --TEST--
Directly modifying an unreferenced array when foreach'ing over it while using &$value syntax.
---XFAIL--
-Needs major foreach changes to get sane behavior
--FILE--
<?php
@@ -70,7 +68,7 @@ withRefValue(3, $transform); withRefValue(4, $transform);
?>
---EXPECTF--
+--EXPECT--
Popping elements off end of an unreferenced array, using &$value.
---( Array with 1 element(s): )---
@@ -95,9 +93,10 @@ array(2) { }
--> Do loop:
iteration 0: $k=0; $v=v.0
- iteration 1: $k=0; $v=v.0
--> State of array after loop:
-array(0) {
+array(1) {
+ [0]=>
+ &string(3) "v.0"
}
---( Array with 3 element(s): )---
@@ -134,10 +133,12 @@ array(4) { --> Do loop:
iteration 0: $k=0; $v=v.0
iteration 1: $k=1; $v=v.1
- iteration 2: $k=0; $v=v.0
- iteration 3: $k=0; $v=v.0
--> State of array after loop:
-array(0) {
+array(2) {
+ [0]=>
+ string(3) "v.0"
+ [1]=>
+ &string(3) "v.1"
}
@@ -289,12 +290,28 @@ array(1) { }
--> Do loop:
iteration 0: $k=0; $v=v.0
+ iteration 1: $k=1; $v=new.0
+ iteration 2: $k=2; $v=new.1
+ iteration 3: $k=3; $v=new.2
+ iteration 4: $k=4; $v=new.3
+ iteration 5: $k=5; $v=new.4
+ ** Stuck in a loop! **
--> State of array after loop:
-array(2) {
+array(7) {
[0]=>
- &string(3) "v.0"
+ string(3) "v.0"
[1]=>
string(5) "new.0"
+ [2]=>
+ string(5) "new.1"
+ [3]=>
+ string(5) "new.2"
+ [4]=>
+ string(5) "new.3"
+ [5]=>
+ &string(5) "new.4"
+ [6]=>
+ string(5) "new.5"
}
---( Array with 2 element(s): )---
@@ -446,30 +463,17 @@ array(2) { }
--> Do loop:
iteration 0: $k=0; $v=v.0
- iteration 1: $k=0; $v=new.0
- iteration 2: $k=0; $v=new.1
- iteration 3: $k=0; $v=new.2
- iteration 4: $k=0; $v=new.3
- iteration 5: $k=0; $v=new.4
- ** Stuck in a loop! **
+ iteration 1: $k=2; $v=v.1
--> State of array after loop:
-array(8) {
+array(4) {
[0]=>
- string(5) "new.5"
- [1]=>
- &string(5) "new.4"
- [2]=>
- string(5) "new.3"
- [3]=>
- string(5) "new.2"
- [4]=>
string(5) "new.1"
- [5]=>
+ [1]=>
string(5) "new.0"
- [6]=>
+ [2]=>
string(3) "v.0"
- [7]=>
- string(3) "v.1"
+ [3]=>
+ &string(3) "v.1"
}
---( Array with 3 element(s): )---
@@ -484,32 +488,19 @@ array(3) { }
--> Do loop:
iteration 0: $k=0; $v=v.0
- iteration 1: $k=0; $v=new.0
- iteration 2: $k=0; $v=new.1
- iteration 3: $k=0; $v=new.2
- iteration 4: $k=0; $v=new.3
- iteration 5: $k=0; $v=new.4
- ** Stuck in a loop! **
+ iteration 1: $k=3; $v=v.2
--> State of array after loop:
-array(9) {
+array(5) {
[0]=>
- string(5) "new.5"
- [1]=>
- &string(5) "new.4"
- [2]=>
- string(5) "new.3"
- [3]=>
- string(5) "new.2"
- [4]=>
string(5) "new.1"
- [5]=>
+ [1]=>
string(5) "new.0"
- [6]=>
+ [2]=>
string(3) "v.0"
- [7]=>
+ [3]=>
string(3) "v.1"
- [8]=>
- string(3) "v.2"
+ [4]=>
+ &string(3) "v.2"
}
---( Array with 4 element(s): )---
@@ -526,32 +517,19 @@ array(4) { }
--> Do loop:
iteration 0: $k=0; $v=v.0
- iteration 1: $k=0; $v=new.0
- iteration 2: $k=0; $v=new.1
- iteration 3: $k=0; $v=new.2
- iteration 4: $k=0; $v=new.3
- iteration 5: $k=0; $v=new.4
- ** Stuck in a loop! **
+ iteration 1: $k=4; $v=v.3
--> State of array after loop:
-array(10) {
+array(6) {
[0]=>
- string(5) "new.5"
- [1]=>
- &string(5) "new.4"
- [2]=>
- string(5) "new.3"
- [3]=>
- string(5) "new.2"
- [4]=>
string(5) "new.1"
- [5]=>
+ [1]=>
string(5) "new.0"
- [6]=>
+ [2]=>
string(3) "v.0"
- [7]=>
+ [3]=>
string(3) "v.1"
- [8]=>
+ [4]=>
string(3) "v.2"
- [9]=>
- string(3) "v.3"
+ [5]=>
+ &string(3) "v.3"
}
|