summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-11 22:49:19 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-11 22:49:19 +0100
commit8c73a24872b5589cbb714be9c8588c7bf81c8563 (patch)
treed99c45763b66fefdfca2408713ae2a6927f1f90e /include
parent41d008988b482c643bd11464ba071de05f183d84 (diff)
implemented __toString, __toInteger, __toFloat and __toBool methods
Diffstat (limited to 'include')
-rw-r--r--include/base.h41
-rw-r--r--include/classbase.h9
-rw-r--r--include/type.h2
3 files changed, 51 insertions, 1 deletions
diff --git a/include/base.h b/include/base.h
index ed6936d..6541549 100644
--- a/include/base.h
+++ b/include/base.h
@@ -179,6 +179,47 @@ public:
*/
virtual Value __invoke(Parameters &params);
+ /**
+ * Cast the object to a string
+ *
+ * This method is called when an object is casted to a string, or when
+ * it is used in a string context
+ *
+ * @return Value The object as a string
+ */
+ virtual Value __toString();
+
+ /**
+ * Cast the object to an integer
+ *
+ * This method is called when an object is casted to an integer, or when
+ * it is used in an integer context
+ *
+ * @return int Integer value
+ */
+ virtual long __toInteger();
+
+ /**
+ * Cast the object to a float
+ *
+ * This method is called when an object is casted to a float, or when it
+ * is used in a float context
+ *
+ * @return double Floating point value
+ */
+ virtual double __toFloat();
+
+ /**
+ * Cast the object to a boolean
+ *
+ * This method is called when an object is casted to a bool, or when it
+ * is used in a boolean context
+ *
+ * @return bool
+ */
+ virtual bool __toBool();
+
+
private:
/**
* Store the object in the zend object cache
diff --git a/include/classbase.h b/include/classbase.h
index 6dba316..da027ab 100644
--- a/include/classbase.h
+++ b/include/classbase.h
@@ -374,6 +374,15 @@ private:
static int getClosure(struct _zval_struct *object, struct _zend_class_entry **entry, union _zend_function **func, struct _zval_struct **object_ptr);
/**
+ * Function to cast the object to a different type
+ * @param object
+ * @param retval
+ * @param type
+ * @return int
+ */
+ static int cast(struct _zval_struct *object, struct _zval_struct *retval, int type);
+
+ /**
* Name of the class
* @var string
*/
diff --git a/include/type.h b/include/type.h
index bec0fd5..e5ebeda 100644
--- a/include/type.h
+++ b/include/type.h
@@ -21,7 +21,7 @@ enum class Type : unsigned char {
Null = 0,
Numeric = 1,
Float = 2,
- Bool = 3,
+ Boolean = 3,
Array = 4,
Object = 5,
String = 6,