/** * 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 single static function direct on a zend_class_entry which requires parameters */ int phalcon_call_static_ce_func_params(zval *return_value, zend_class_entry *ce, char *method_name, int method_len, zend_uint param_count, zval *params[], int noreturn TSRMLS_DC){ zval *fn; int status; if (!noreturn) { ALLOC_INIT_ZVAL(return_value); } ALLOC_INIT_ZVAL(fn); array_init(fn); add_next_index_stringl(fn, ce->name, ce->name_length, 0); add_next_index_stringl(fn, method_name, method_len, 0); status = PHALCON_CALL_USER_FUNCTION(CG(function_table), NULL, fn, return_value, param_count, params TSRMLS_CC); if (status == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function %s::%s()", ce->name, method_name); } if (!noreturn) { zval_ptr_dtor(&return_value); } if (EG(exception)){ status = FAILURE; } if (status == FAILURE) { phalcon_memory_restore_stack(TSRMLS_C); } return status; }
/** * This is a function to call PHP functions in a old-style secure way */ static inline int phalcon_call_func_normal(zval *return_value, char *func_name, int func_length, int noreturn TSRMLS_DC){ zval *fn = NULL; int status = FAILURE; if (!noreturn) { ALLOC_INIT_ZVAL(return_value); } PHALCON_ALLOC_ZVAL(fn); ZVAL_STRINGL(fn, func_name, func_length, 0); status = phalcon_call_user_function(CG(function_table), NULL, fn, return_value, 0, NULL TSRMLS_CC); if (status == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function %s()", func_name); } 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 single static function which not requires parameters */ int phalcon_call_static_func(zval *return_value, char *class_name, int class_length, char *method_name, int method_len, int noreturn TSRMLS_DC){ zval *fn; int status = FAILURE; if (!noreturn) { ALLOC_INIT_ZVAL(return_value); } ALLOC_INIT_ZVAL(fn); array_init(fn); add_next_index_stringl(fn, class_name, class_length, 1); add_next_index_stringl(fn, method_name, method_len, 1); status = phalcon_call_user_function(CG(function_table), NULL, fn, return_value, 0, NULL TSRMLS_CC); if (status == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function %s::%s()", class_name, method_name); } 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; }
/** * Reads class constant from string name and returns its value */ int phalcon_get_class_constant(zval *return_value, zend_class_entry *ce, char *constant_name, unsigned int constant_length TSRMLS_DC) { zval **result_ptr; if (phalcon_hash_find(&ce->constants_table, constant_name, constant_length, (void **) &result_ptr) != SUCCESS) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Undefined class constant '%s::%s'", ce->name, constant_name); phalcon_memory_restore_stack(TSRMLS_C); return FAILURE; } ZVAL_ZVAL(return_value, *result_ptr, 1, 0); return SUCCESS; }
/** * Call single static function on a zval which requires parameters */ inline int phalcon_call_static_zval_func_params(zval *return_value, zval *mixed_name, char *method_name, int method_len, zend_uint param_count, zval *params[], int noreturn TSRMLS_DC){ zval *fn; int status = FAILURE; if (!noreturn) { ALLOC_INIT_ZVAL(return_value); } ALLOC_INIT_ZVAL(fn); array_init(fn); add_next_index_zval(fn, mixed_name); add_next_index_stringl(fn, method_name, method_len, 1); status = phalcon_call_user_function(CG(function_table), NULL, fn, return_value, param_count, params TSRMLS_CC); if (status == FAILURE) { if(Z_TYPE_P(mixed_name) == IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function %s::%s()", Z_STRVAL_P(mixed_name), method_name); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function not-callable::%s()", method_name); } } 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; }
/** * This is a function to call PHP functions in a old-style secure way */ inline int phalcon_call_func_normal(zval *return_value, char *func_name, int func_length, int noreturn TSRMLS_DC){ zval *fn = NULL; int status = FAILURE; zval *local_retval_ptr = NULL; if (!noreturn) { ALLOC_INIT_ZVAL(return_value); } PHALCON_ALLOC_ZVAL(fn); ZVAL_STRINGL(fn, func_name, func_length, 1); status = PHALCON_CALL_USER_FUNCTION(CG(function_table), NULL, fn, return_value, 0, NULL TSRMLS_CC); if (status == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function %s()", func_name); } zval_ptr_dtor(&fn); if (local_retval_ptr) { COPY_PZVAL_TO_ZVAL(*return_value, local_retval_ptr); } if (!noreturn) { zval_ptr_dtor(&return_value); } if (EG(exception)){ status = FAILURE; } if (status == FAILURE) { phalcon_memory_restore_stack(TSRMLS_C); } return status; }