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