/** * This function implements a secure old-style way to call functions */ static inline int phalcon_call_method_normal(zval *return_value, zval *object, char *method_name, int method_len, int check, int noreturn TSRMLS_DC){ zval *fn = NULL; int status = FAILURE; zend_class_entry *ce, *active_scope = NULL; if (Z_TYPE_P(object) != IS_OBJECT) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to method %s() on a non object", method_name); phalcon_memory_restore_stack(TSRMLS_C); return FAILURE; } ce = Z_OBJCE_P(object); if (check) { if (!zend_hash_exists(&ce->function_table, method_name, method_len+1)) { return SUCCESS; } } if (!noreturn) { ALLOC_INIT_ZVAL(return_value); } PHALCON_ALLOC_ZVAL(fn); ZVAL_STRINGL(fn, method_name, method_len, 0); active_scope = EG(scope); /* Find class_entry scope */ if (ce->parent) { phalcon_find_scope(ce, method_name, method_len TSRMLS_CC); } else { EG(scope) = ce; } status = phalcon_call_user_function(&ce->function_table, &object, fn, return_value, 0, NULL TSRMLS_CC); if (status == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined method %s()", method_name); } EG(scope) = active_scope; ZVAL_NULL(fn); zval_ptr_dtor(&fn); if (!noreturn) { zval_ptr_dtor(&return_value); } if (EG(exception)) { status = FAILURE; } if (status == FAILURE) { phalcon_memory_restore_stack(TSRMLS_C); } return status; }
/** * Call methods that require parameters in a old-style secure way */ inline int phalcon_call_method_params_normal(zval *return_value, zval *object, char *method_name, int method_len, zend_uint param_count, zval *params[], int check, int noreturn TSRMLS_DC){ zval *fn = NULL; int status = FAILURE; zend_class_entry *ce, *active_scope = NULL; if (check) { if (!zend_hash_exists(&Z_OBJCE_P(object)->function_table, method_name, method_len+1)) { return SUCCESS; } } if (!noreturn) { ALLOC_INIT_ZVAL(return_value); } PHALCON_ALLOC_ZVAL(fn); ZVAL_STRINGL(fn, method_name, method_len, 1); if (Z_TYPE_P(object) == IS_OBJECT) { active_scope = EG(scope); ce = Z_OBJCE_P(object); phalcon_find_scope(ce, method_name, method_len TSRMLS_CC); status = PHALCON_CALL_USER_FUNCTION(&ce->function_table, &object, fn, return_value, param_count, params TSRMLS_CC); if (status == FAILURE) { EG(scope) = active_scope; php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined method %s() on class %s", Z_STRVAL_P(fn), Z_OBJCE_P(object)->name); status = FAILURE; } EG(scope) = active_scope; } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to method %s() on a non object", Z_STRVAL_P(fn)); status = FAILURE; } zval_ptr_dtor(&fn); if (!noreturn) { zval_ptr_dtor(&return_value); return_value = NULL; } if (EG(exception)){ status = FAILURE; } if (status == FAILURE) { phalcon_memory_restore_stack(TSRMLS_C); } return status; }
/** * Call self-class static function which requires parameters */ int phalcon_call_self_func_params(zval *return_value, zval *object, char *method_name, int method_len, zend_uint param_count, zval *params[], int noreturn TSRMLS_DC){ int success; zend_class_entry *active_scope = NULL; if (object) { active_scope = EG(scope); phalcon_find_scope(Z_OBJCE_P(object), method_name, method_len TSRMLS_CC); } success = phalcon_call_static_func_params(return_value, "self", strlen("self"), method_name, method_len, param_count, params, noreturn TSRMLS_CC); if (object) { EG(scope) = active_scope; } return success; }
/** * Call self-class static function which not requires parameters */ int phalcon_call_self_func(zval *return_value, zval *object, char *method_name, int method_len, int noreturn TSRMLS_DC){ int success; zend_class_entry *active_scope = NULL; if (object) { active_scope = EG(scope); phalcon_find_scope(Z_OBJCE_P(object), method_name, method_len TSRMLS_CC); } success = phalcon_call_static_func(return_value, SL("self"), method_name, method_len, noreturn TSRMLS_CC); if (object) { EG(scope) = active_scope; } return success; }
/** * Call method on an object which not requires parameters * */ int phalcon_call_method(zval *return_value, zval *object, char *method_name, int method_len, int check, int noreturn TSRMLS_DC){ zval *fn = NULL; int status = FAILURE; zend_class_entry *active_scope = NULL; if (check) { if (!zend_hash_exists(&Z_OBJCE_P(object)->function_table, method_name, strlen(method_name)+1)) { return FAILURE; } } if(!noreturn){ ALLOC_INIT_ZVAL(return_value); } PHALCON_ALLOC_ZVAL(fn); ZVAL_STRINGL(fn, method_name, method_len, 1); if (Z_TYPE_P(object) == IS_OBJECT) { active_scope = EG(scope); phalcon_find_scope(Z_OBJCE_P(object), method_name, method_len TSRMLS_CC); status = call_user_function(&Z_OBJCE_P(object)->function_table, &object, fn, return_value, 0, NULL TSRMLS_CC); if (status == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined method %s()", Z_STRVAL_P(fn)); return FAILURE; } EG(scope) = active_scope; } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to method %s() on a non object", Z_STRVAL_P(fn)); return FAILURE; } zval_ptr_dtor(&fn); if (!noreturn) { zval_ptr_dtor(&return_value); } return status; }