/* {{{ write_property handler */ static zval *Transliterator_write_property( zval *object, zval *member, zval *value, void **cache_slot ) { zend_class_entry *scope; TRANSLITERATOR_PROPERTY_HANDLER_PROLOG; if (EG(fake_scope)) { scope = EG(fake_scope); } else { scope = zend_get_executed_scope(); } if( ( scope != Transliterator_ce_ptr ) && ( zend_binary_strcmp( "id", sizeof( "id" ) - 1, Z_STRVAL_P( member ), Z_STRLEN_P( member ) ) == 0 ) ) { php_error_docref0( NULL, E_WARNING, "The property \"id\" is read-only" ); } else { value = zend_std_write_property( object, member, value, cache_slot ); } TRANSLITERATOR_PROPERTY_HANDLER_EPILOG; return value; }
static void zend_closure_call_magic(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ { zend_fcall_info fci; zend_fcall_info_cache fcc; zval params[2]; memset(&fci, 0, sizeof(zend_fcall_info)); memset(&fci, 0, sizeof(zend_fcall_info_cache)); fci.size = sizeof(zend_fcall_info); fci.retval = return_value; fcc.initialized = 1; fcc.function_handler = (zend_function *) EX(func)->common.arg_info; fci.params = params; fci.param_count = 2; ZVAL_STR(&fci.params[0], EX(func)->common.function_name); array_init(&fci.params[1]); zend_copy_parameters_array(ZEND_NUM_ARGS(), &fci.params[1]); fci.object = Z_OBJ(EX(This)); fcc.object = Z_OBJ(EX(This)); fcc.calling_scope = zend_get_executed_scope(); zend_call_function(&fci, &fcc); zval_ptr_dtor(&fci.params[0]); zval_ptr_dtor(&fci.params[1]); }
/** * Returns the called in class in the current scope */ void zephir_get_called_class(zval *return_value) { #if PHP_VERSION_ID >= 70100 zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data)); if (called_scope) { ZVAL_STR(return_value, zend_string_dup(called_scope->name, 0)); } if (!zend_get_executed_scope()) { php_error_docref(NULL, E_WARNING, "zephir_get_called_class() called from outside a class"); } #else if (EG(current_execute_data)->called_scope) { zend_string *ret = EG(current_execute_data)->called_scope->name; zend_string_addref(ret); RETURN_STR(ret); } if (!EG(scope)) { php_error_docref(NULL, E_WARNING, "zephir_get_called_class() called from outside a class"); } #endif }
/** * Creates a unique key to cache the current method/function call address for the current scope */ static ulong zephir_make_fcall_info_key(char **result, size_t *length, const zend_class_entry *obj_ce, zephir_call_type type, zephir_fcall_info *info) { const zend_class_entry *calling_scope; char *buf = NULL, *c; size_t l = 0, len = 0; const size_t ppzce_size = sizeof(zend_class_entry**); ulong hash = 5381; #if PHP_VERSION_ID >= 70100 calling_scope = zend_get_executed_scope(); #else calling_scope = EG(scope); #endif *result = NULL; *length = 0; if (calling_scope && type == zephir_fcall_parent) { calling_scope = calling_scope->parent; if (UNEXPECTED(!calling_scope)) { return 0; } } else if (type == zephir_fcall_static) { #if PHP_VERSION_ID >= 70100 calling_scope = zend_get_called_scope(EG(current_execute_data)); #else calling_scope = EG(current_execute_data)->called_scope; #endif if (UNEXPECTED(!calling_scope)) { return 0; } } if ( calling_scope && obj_ce && calling_scope != obj_ce && !instanceof_function(obj_ce, calling_scope) && !instanceof_function(calling_scope, obj_ce) ) { calling_scope = NULL; } switch (info->type) { case ZEPHIR_FCALL_TYPE_FUNC: l = (size_t)(info->func_length) + 1; c = (char*) info->func_name; len = 2 * ppzce_size + l + 1; buf = emalloc(len); memcpy(buf, c, l); memcpy(buf + l, &calling_scope, ppzce_size); memcpy(buf + l + ppzce_size, &obj_ce, ppzce_size); buf[len - 1] = '\0'; break; case ZEPHIR_FCALL_TYPE_CLASS_SELF_METHOD: case ZEPHIR_FCALL_TYPE_CLASS_STATIC_METHOD: case ZEPHIR_FCALL_TYPE_CLASS_PARENT_METHOD: l = (size_t)(info->func_length) + 2; /* reserve 1 char for fcall-type */ c = (char*) info->func_name; len = 2 * ppzce_size + l + 1; buf = emalloc(len); buf[0] = info->type; memcpy(buf + 1, c, l - 1); memcpy(buf + l, &calling_scope, ppzce_size); memcpy(buf + l + ppzce_size, &obj_ce, ppzce_size); buf[len - 1] = '\0'; break; case ZEPHIR_FCALL_TYPE_CE_METHOD: case ZEPHIR_FCALL_TYPE_ZVAL_METHOD: l = (size_t)(info->func_length) + 1; c = (char*) info->func_name; len = 2 * ppzce_size + l + 1; buf = emalloc(len); memcpy(buf, c, l); memcpy(buf + l, &calling_scope, ppzce_size); memcpy(buf + l + ppzce_size, &obj_ce, ppzce_size); buf[len - 1] = '\0'; break; } if (EXPECTED(buf != NULL)) { size_t i; for (i = 0; i < l; ++i) { char c = buf[i]; c = tolower_map[(unsigned char)c]; buf[i] = c; hash = (hash << 5) + hash + c; } for (i = l; i < len; ++i) { char c = buf[i]; hash = (hash << 5) + hash + c; } } *result = buf; *length = len; return hash; }