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