Annotation of embedaddon/php/ext/standard/tests/array/array_fill_keys_variation2.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test array_fill_keys() function : variation of parameter
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : proto array array_fill_keys(array keys, mixed val)
! 6: * Description: Create an array using the elements of the first parameter as keys each initialized to val
! 7: * Source code: ext/standard/array.c
! 8: * Alias to functions:
! 9: */
! 10:
! 11: /* Testing with reference types for the arguments */
! 12:
! 13: echo "*** Testing array_fill_keys() : parameter variations ***\n";
! 14:
! 15: $nullVal = null;
! 16: $simpleStr = "simple";
! 17: $refString = &$simpleStr;
! 18: $fp = fopen(__FILE__, "r");
! 19: $emptyArr = array();
! 20: $bool = false;
! 21: $float = 2.4;
! 22:
! 23: class classA {
! 24: public function __toString() { return "Class A object"; }
! 25: }
! 26: $obj = new classA();
! 27:
! 28:
! 29: echo "\n-- Testing array_fill_keys() function with reference value --\n";
! 30: $keyedArray = array("one", "two");
! 31: var_dump(array_fill_keys($keyedArray, $refString));
! 32:
! 33: echo "\n-- Testing array_fill_keys() function with reference keys --\n";
! 34: $refKeys = array("one", &$simpleStr);
! 35: $res = array_fill_keys($refKeys, $simpleStr);
! 36: var_dump($res);
! 37: $simpleStr = "bob";
! 38: var_dump($res);
! 39:
! 40:
! 41: echo "\n-- Testing array_fill_keys() function with reference array input --\n";
! 42: $newArray = array("one", "two");
! 43: $refArray = &$newArray;
! 44: var_dump(array_fill_keys($refArray, $simpleStr));
! 45:
! 46: fclose($fp);
! 47: echo "Done";
! 48: ?>
! 49: --EXPECTF--
! 50: *** Testing array_fill_keys() : parameter variations ***
! 51:
! 52: -- Testing array_fill_keys() function with reference value --
! 53: array(2) {
! 54: ["one"]=>
! 55: string(6) "simple"
! 56: ["two"]=>
! 57: string(6) "simple"
! 58: }
! 59:
! 60: -- Testing array_fill_keys() function with reference keys --
! 61: array(2) {
! 62: ["one"]=>
! 63: string(6) "simple"
! 64: ["simple"]=>
! 65: string(6) "simple"
! 66: }
! 67: array(2) {
! 68: ["one"]=>
! 69: string(6) "simple"
! 70: ["simple"]=>
! 71: string(6) "simple"
! 72: }
! 73:
! 74: -- Testing array_fill_keys() function with reference array input --
! 75: array(2) {
! 76: ["one"]=>
! 77: string(3) "bob"
! 78: ["two"]=>
! 79: string(3) "bob"
! 80: }
! 81: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>