blob: 8a384dc62f4e452b96bfdf1431b2075017d000b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/**
*
* Test Classes and objects
* 003-comparable.phpt
*
*/
/**
* Set up namespace
*/
namespace TestBaseClass {
/**
* Test custom comparison operator
*/
class Comparable : public Php::Base
{
private:
/**
* Internal value of the class
* @var int
*/
static int count;
int _nom;
int _value;
public:
/**
* C++ constructor
*/
Comparable()
{
// start with random value
//_value = rand();
_nom = ++count;
_value = _nom%2+1;
}
/**
* C++ destructor
*/
virtual ~Comparable() {}
/**
* Cast the object to a string
* @return std::string
*/
std::string __toString()
{
return "Obj#" + std::to_string(_nom) + "(" + std::to_string(_value) + ")";
}
/**
* Compare with a different object
* @param that
* @return int
*/
int __compare(const Comparable &that) const
{
return _value - that._value;
}
};
int Comparable::count = 0;
/**
* End of namespace
*/
}
|