1--TEST--
2Test natcasesort() function : object functionality - mixed visibility within objects
3--FILE--
4<?php
5/*
6 * Pass natcasesort() an array of objects which have properties of different
7 * visibilities to test how it re-orders the array.
8 */
9
10echo "*** Testing natcasesort() : object functionality ***\n";
11
12// class declaration for string objects
13class for_string_natcasesort
14{
15    public $public_class_value;
16    private $private_class_value;
17    protected $protected_class_value;
18    // initializing object member value
19    function __construct($value1, $value2,$value3){
20        $this->public_class_value = $value1;
21        $this->private_class_value = $value2;
22        $this->protected_class_value = $value3;
23    }
24
25    // return string value
26    function __tostring() {
27        return (string)$this->public_class_value;
28    }
29
30}
31
32// array of string objects
33$unsorted_str_obj = array (
34new for_string_natcasesort("axx","AXX","ass"),
35new for_string_natcasesort("t","eee","abb"),
36new for_string_natcasesort("w","W", "c"),
37new for_string_natcasesort("py","PY", "pt"),
38);
39
40
41echo "\n-- Testing natcasesort() by supplying object arrays --\n";
42
43// testing natcasesort() function by supplying string object array
44$temp_array = $unsorted_str_obj;
45var_dump(natcasesort($temp_array) );
46var_dump($temp_array);
47
48echo "Done";
49?>
50--EXPECTF--
51*** Testing natcasesort() : object functionality ***
52
53-- Testing natcasesort() by supplying object arrays --
54bool(true)
55array(4) {
56  [0]=>
57  object(for_string_natcasesort)#%d (3) {
58    ["public_class_value"]=>
59    string(3) "axx"
60    ["private_class_value":"for_string_natcasesort":private]=>
61    string(3) "AXX"
62    ["protected_class_value":protected]=>
63    string(3) "ass"
64  }
65  [3]=>
66  object(for_string_natcasesort)#%d (3) {
67    ["public_class_value"]=>
68    string(2) "py"
69    ["private_class_value":"for_string_natcasesort":private]=>
70    string(2) "PY"
71    ["protected_class_value":protected]=>
72    string(2) "pt"
73  }
74  [1]=>
75  object(for_string_natcasesort)#%d (3) {
76    ["public_class_value"]=>
77    string(1) "t"
78    ["private_class_value":"for_string_natcasesort":private]=>
79    string(3) "eee"
80    ["protected_class_value":protected]=>
81    string(3) "abb"
82  }
83  [2]=>
84  object(for_string_natcasesort)#%d (3) {
85    ["public_class_value"]=>
86    string(1) "w"
87    ["private_class_value":"for_string_natcasesort":private]=>
88    string(1) "W"
89    ["protected_class_value":protected]=>
90    string(1) "c"
91  }
92}
93Done
94