summaryrefslogtreecommitdiff
path: root/tests/cpp/include/variables/005-cast-objects-to-scalars.h
blob: f053c4d6de3b8fbb3026b137673283a2cbb38283 (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
75
/**
 *
 *  Test variables
 *	005-cast-objects-to-scalars.phpt
 *
 */



/**
 *  Set up namespace
 */
namespace TestVariables {

	/**
	 *  A sample class, with methods to cast objects to scalars
	 */
	class Obj2Scalar : public Php::Base
	{
	public:
	    /**
	     *  C++ constructor and C++ destructpr
	     */
	    Obj2Scalar() {}
	    virtual ~Obj2Scalar() {}

	    /**
	     *  Cast to a string
	     *
	     *  Note that now we use const char* as return value, and not Php::Value.
	     *  The __toString function is detected at compile time, and it does
	     *  not have a fixed signature. You can return any value that can be picked
	     *  up by a Php::Value object.
	     *
	     *  @return const char *
	     */
	    const char *__toString()
	    {
	        return "Mount Meru, also called Sumeru (Sanskrit)";
	    }
	    
	    /**
	     *  Cast to a integer
	     *  @return long
	     */
	    long __toInteger()
	    {
	        return 27032014;
	    }
	    
	    /**
	     *  Cast to a floating point number
	     *  @return double
	     */
	    double __toFloat()
	    {
	        return 3.14159265359;
	    }
	    
	    /**
	     *  Cast to a boolean
	     *  @return bool
	     */
	    bool __toBool()
	    {
	        return true;
	    }
	};


/**
 *  End of namespace
 */
}