summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/array_splice_variation1.phpt
diff options
context:
space:
mode:
authorRobert Nicholson <nicholsr@php.net>2007-10-26 11:07:13 +0000
committerRobert Nicholson <nicholsr@php.net>2007-10-26 11:07:13 +0000
commit9e761076b8ed99ffa2b0da3e8522c3c625f56d4f (patch)
treef02e9fc1fb3645cd68fbd186e46116924e4c64d0 /ext/standard/tests/array/array_splice_variation1.phpt
parent656d0e468bbd462c660d1e12cb9151e66d1bac54 (diff)
downloadphp-git-9e761076b8ed99ffa2b0da3e8522c3c625f56d4f.tar.gz
new testcases for array_splice
Diffstat (limited to 'ext/standard/tests/array/array_splice_variation1.phpt')
-rw-r--r--ext/standard/tests/array/array_splice_variation1.phpt111
1 files changed, 111 insertions, 0 deletions
diff --git a/ext/standard/tests/array/array_splice_variation1.phpt b/ext/standard/tests/array/array_splice_variation1.phpt
new file mode 100644
index 0000000000..99685feb28
--- /dev/null
+++ b/ext/standard/tests/array/array_splice_variation1.phpt
@@ -0,0 +1,111 @@
+--TEST--
+Test array_splice() function : usage variations - references
+
+--INI--
+--FILE--
+<?php
+/*
+ * proto array array_splice(array input, int offset [, int length [, array replacement]])
+ * Function is implemented in ext/standard/array.c
+*/
+
+
+echo "test behaviour when input array is in a reference set\n";
+
+$input_array=array (array(1,2));
+$input_array[]=&$input_array[0];
+var_dump (array_splice ($input_array[0],1,1));
+var_dump ($input_array);
+
+echo "Test behaviour of input arrays containing references \n";
+/*
+ * There are three regions to test:, before cut, the cut and after the cut.
+ * For reach we check a plain value, a reference value with integer key and a
+ * reference value with a string key.
+ */
+$numbers=array(0,1,2,3,4,5,6,7,8,9,10,11,12);
+$input_array=array(0,1,&$numbers[2],"three"=>&$numbers[3],4,&$numbers[5],"six"=>&$numbers[6],7,&$numbers[8],"nine"=>&$numbers[9]);
+var_dump (array_splice ($input_array,4,3));
+var_dump ($input_array);
+
+echo "Test behaviour of replacement array containing references \n";
+
+$three=3;
+$four=4;
+$input_array=array (0,1,2);
+$b=array(&$three,"fourkey"=>&$four);
+array_splice ($input_array,-1,1,$b);
+var_dump ($input_array);
+
+echo "Test behaviour of replacement which is part of reference set \n";
+
+$int=3;
+$input_array=array (1,2);
+$b=&$int;
+
+array_splice ($input_array,-1,1,$b);
+var_dump ($input_array);
+echo "Done\n";
+?>
+--EXPECT--
+test behaviour when input array is in a reference set
+array(1) {
+ [0]=>
+ int(2)
+}
+array(2) {
+ [0]=>
+ &array(1) {
+ [0]=>
+ int(1)
+ }
+ [1]=>
+ &array(1) {
+ [0]=>
+ int(1)
+ }
+}
+Test behaviour of input arrays containing references
+array(3) {
+ [0]=>
+ int(4)
+ [1]=>
+ &int(5)
+ ["six"]=>
+ &int(6)
+}
+array(7) {
+ [0]=>
+ int(0)
+ [1]=>
+ int(1)
+ [2]=>
+ &int(2)
+ ["three"]=>
+ &int(3)
+ [3]=>
+ int(7)
+ [4]=>
+ &int(8)
+ ["nine"]=>
+ &int(9)
+}
+Test behaviour of replacement array containing references
+array(4) {
+ [0]=>
+ int(0)
+ [1]=>
+ int(1)
+ [2]=>
+ &int(3)
+ [3]=>
+ &int(4)
+}
+Test behaviour of replacement which is part of reference set
+array(2) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(3)
+}
+Done \ No newline at end of file