xref: /PHP-7.1/ext/spl/tests/fixedarray_020.phpt (revision f60da355)
1--TEST--
2SPL: FixedArray: fromArray/toArray + get_properties
3--FILE--
4<?php
5$a = array(1=>'foo', 2=>'bar', 0=>'gee');
6$fa = SplFixedArray::fromArray($a, false);
7var_dump(count($fa), $fa->toArray() === array_values($a));
8
9$fa = SplFixedArray::fromArray($a, true);
10var_dump(count($fa), $fa->toArray() === $a, $fa->toArray() === (array)$fa);
11
12try {
13    echo "From Array with string keys, no preserve\n";
14    SplFixedArray::fromArray(array("foo"=>"bar"), false);
15    echo "No exception\n";
16} catch (Exception $e) {
17    echo "Exception: ".$e->getMessage()."\n";
18}
19try {
20    echo "From Array with string keys, preserve\n";
21    SplFixedArray::fromArray(array("foo"=>"bar"), true);
22    echo "No exception\n";
23} catch (Exception $e) {
24    echo "Exception: ".$e->getMessage()."\n";
25}
26?>
27--EXPECT--
28int(3)
29bool(true)
30int(3)
31bool(false)
32bool(true)
33From Array with string keys, no preserve
34No exception
35From Array with string keys, preserve
36Exception: array must contain only positive integer keys
37