summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.c
diff options
context:
space:
mode:
authorAndrei Zmievski <andrei@php.net>2002-07-30 04:07:15 +0000
committerAndrei Zmievski <andrei@php.net>2002-07-30 04:07:15 +0000
commit82c72f2799927e5051780025924c82f4801e478d (patch)
tree81d031524f748dab93466bc5af0502ae42f6e868 /Zend/zend_operators.c
parent84ae5adf29f9cd11ae5f06579dc51ff57c444fa2 (diff)
downloadphp-git-82c72f2799927e5051780025924c82f4801e478d.tar.gz
@- Adding 'is' operator that can be used to check the type of a variable,
@ or its class. (Andrei)
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r--Zend/zend_operators.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 5fdd1c1eb6..1eae6c036a 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -1365,6 +1365,60 @@ ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2 TSR
}
+ZEND_API int is_type_function(zval *result, zval *op1, zend_class_entry *class, int type TSRMLS_DC)
+{
+ if (class) {
+ if (Z_TYPE_P(op1) == IS_OBJECT) {
+ zend_class_entry *ce;
+ for (ce = Z_OBJCE_P(op1); ce != NULL; ce = ce->parent) {
+ if (ce == class) {
+ ZVAL_BOOL(result, 1);
+ return SUCCESS;
+ }
+ }
+ ZVAL_BOOL(result, 0);
+ } else {
+ ZVAL_BOOL(result, 0);
+ }
+ return SUCCESS;
+ }
+
+ switch (type) {
+ case IS_NULL:
+ ZVAL_BOOL(result, Z_TYPE_P(op1) == IS_NULL);
+ break;
+
+ case IS_LONG:
+ ZVAL_BOOL(result, Z_TYPE_P(op1) == IS_LONG);
+ break;
+
+ case IS_DOUBLE:
+ ZVAL_BOOL(result, Z_TYPE_P(op1) == IS_DOUBLE);
+ break;
+
+ case IS_STRING:
+ ZVAL_BOOL(result, Z_TYPE_P(op1) == IS_STRING);
+ break;
+
+ case IS_ARRAY:
+ ZVAL_BOOL(result, Z_TYPE_P(op1) == IS_ARRAY);
+ break;
+
+ case IS_OBJECT:
+ ZVAL_BOOL(result, Z_TYPE_P(op1) == IS_OBJECT);
+ break;
+
+ case IS_BOOL:
+ ZVAL_BOOL(result, Z_TYPE_P(op1) == IS_BOOL);
+ break;
+
+ default:
+ zend_error(E_ERROR, "Unknown operand type");
+ return FAILURE;
+ }
+ return SUCCESS;
+}
+
#define LOWER_CASE 1
#define UPPER_CASE 2
#define NUMERIC 3