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--EXPECTF--
52*** Testing natcasesort() : object functionality ***
53
54-- Testing natcasesort() by supplying various object arrays --
55bool(true)
56array(8) {
57  [4]=>
58  object(for_string_natcasesort)#%d (1) {
59    ["class_value"]=>
60    string(5) "apple"
61  }
62  [7]=>
63  object(for_string_natcasesort)#%d (1) {
64    ["class_value"]=>
65    string(5) "aPPle"
66  }
67  [0]=>
68  object(for_string_natcasesort)#%d (1) {
69    ["class_value"]=>
70    string(3) "axx"
71  }
72  [6]=>
73  object(for_string_natcasesort)#%d (1) {
74    ["class_value"]=>
75    string(5) "Lemon"
76  }
77  [5]=>
78  object(for_string_natcasesort)#%d (1) {
79    ["class_value"]=>
80    string(6) "Orange"
81  }
82  [3]=>
83  object(for_string_natcasesort)#%d (1) {
84    ["class_value"]=>
85    string(2) "py"
86  }
87  [1]=>
88  object(for_string_natcasesort)#%d (1) {
89    ["class_value"]=>
90    string(1) "t"
91  }
92  [2]=>
93  object(for_string_natcasesort)#%d (1) {
94    ["class_value"]=>
95    string(1) "w"
96  }
97}
98Done
99