/* {{{ Qconf::getHostNative( .. ) */ static PHP_METHOD(Qconf, getHostNative) { char *path, *idc; size_t path_len, idc_len; int i; long get_flags = QCONF_WAIT; int ret = 0; string_vector_t nodes; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sl", &path, &path_len, &idc, &idc_len, &get_flags) == FAILURE) { RETURN_NULL(); } ret = init_string_vector(&nodes); if (QCONF_OK != ret) { RETVAL_NULL(); } if (QCONF_NOWAIT == get_flags) { ret = qconf_aget_batch_keys_native(path, &nodes, idc); } else { ret = qconf_get_batch_keys_native(path, &nodes, idc); } if (QCONF_OK == ret) { if (nodes.count == 0) { RETVAL_STRINGL("", 0, 1); } else { unsigned int r = rand() % nodes.count; size_t node_len = strlen(nodes.data[r]); RETVAL_STRINGL(nodes.data[r], node_len, 1); } destroy_string_vector(&nodes); } else { RETVAL_NULL(); } return; }
/* {{{ QConfig::GetBatchConf( .. ) */ static PHP_METHOD(QConfig, GetBatchConf) { char *path, *idc; size_t path_len, idc_len; int i; qconf_batch_nodes bnodes; long get_flags = QCONF_WAIT; int ret = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sl", &path, &path_len, &idc, &idc_len, &get_flags) == FAILURE) { RETURN_NULL(); } init_qconf_batch_nodes(&bnodes); if (QCONF_OK != ret) { RETVAL_NULL(); } if (QCONF_NOWAIT == get_flags) { ret = qconf_aget_batch_conf(path, &bnodes, idc); } else { ret = qconf_get_batch_conf(path, &bnodes, idc); } if (QCONF_OK == ret && (bnodes.count >= 0)) { array_init(return_value); for (i = 0; i < bnodes.count; i++) { #if PHP_VERSION_ID >= 70000 add_assoc_string(return_value, bnodes.nodes[i].key, bnodes.nodes[i].value); #else add_assoc_string(return_value, bnodes.nodes[i].key, bnodes.nodes[i].value, 1); #endif } destroy_qconf_batch_nodes(&bnodes); } else { RETVAL_NULL(); } return; }
/* {{{ QConfig::GetBatchKeys( .. ) */ static PHP_METHOD(QConfig, GetBatchKeys) { char *path, *idc; size_t path_len, idc_len; int i; long get_flags = QCONF_WAIT; string_vector_t nodes; int ret = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sl", &path, &path_len, &idc, &idc_len, &get_flags) == FAILURE) { RETURN_NULL(); } init_string_vector(&nodes); if (QCONF_OK != ret) { RETVAL_NULL(); } if (QCONF_NOWAIT == get_flags) { ret = qconf_aget_batch_keys(path, &nodes, idc); } else { ret = qconf_get_batch_keys(path, &nodes, idc); } if (QCONF_OK == ret && (nodes.count >= 0)) { array_init(return_value); for (i = 0; i < nodes.count; i++) { #if PHP_VERSION_ID >= 70000 add_next_index_string(return_value, nodes.data[i]); #else add_next_index_string(return_value, nodes.data[i], 1); #endif } destroy_string_vector(&nodes); } else { RETVAL_NULL(); } return; }
/* {{{ php_xmlreader_string_arg */ static void php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_one_char_t internal_function) { zval *id; size_t name_len = 0; char *retchar = NULL; xmlreader_object *intern; char *name; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { return; } if (!name_len) { php_error_docref(NULL, E_WARNING, "Argument cannot be an empty string"); RETURN_FALSE; } id = getThis(); intern = Z_XMLREADER_P(id); if (intern && intern->ptr) { retchar = (char *)internal_function(intern->ptr, (const unsigned char *)name); } if (retchar) { RETVAL_STRING(retchar); xmlFree(retchar); return; } else { RETVAL_NULL(); } }
PHP_METHOD(MongoDB, setProfilingLevel) { long level; zval *data, *cmd_return; zval **ok; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &level) == FAILURE) { return; } MAKE_STD_ZVAL(data); array_init(data); add_assoc_long(data, "profile", level); MAKE_STD_ZVAL(cmd_return); MONGO_CMD(cmd_return, getThis()); zval_ptr_dtor(&data); if (EG(exception)) { zval_ptr_dtor(&cmd_return); return; } if (zend_hash_find(HASH_P(cmd_return), "ok", 3, (void**)&ok) == SUCCESS && ((Z_TYPE_PP(ok) == IS_BOOL && Z_BVAL_PP(ok)) || Z_DVAL_PP(ok) == 1)) { zend_hash_find(HASH_P(cmd_return), "was", 4, (void**)&ok); RETVAL_ZVAL(*ok, 1, 0); } else { RETVAL_NULL(); } zval_ptr_dtor(&cmd_return); }
PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */ { php_json_parser parser; php_json_parser_init(&parser, return_value, str, str_len, (int)options, (int)depth); if (php_json_yyparse(&parser)) { JSON_G(error_code) = php_json_parser_error_code(&parser); RETVAL_NULL(); return FAILURE; } return SUCCESS; }
static PHP_METHOD(midgard_connection, get_error_string) { RETVAL_NULL(); /* Disable debug log for function call. * It resets error. Keep it like this for backward compatibility */ /* CHECK_MGD; */ if (zend_parse_parameters_none() == FAILURE) return; MidgardConnection *mgd =__midgard_connection_get_ptr(getThis()); const char *err_string = midgard_connection_get_error_string(mgd); RETURN_STRING((gchar *)err_string, 1); }
static PHP_METHOD(midgard_connection, get_user) { RETVAL_NULL(); MidgardConnection *mgd =__midgard_connection_get_ptr(getThis()); CHECK_MGD(mgd); if (zend_parse_parameters_none() == FAILURE) return; MidgardUser *user = midgard_connection_get_user(mgd); if (user == NULL) RETURN_NULL(); g_object_ref(user); // this is a direct-pointer: we need to "ref" it explicitly php_midgard_gobject_new_with_gobject(return_value, php_midgard_user_class, G_OBJECT(user), TRUE TSRMLS_CC); }
static void php_mongo_db_profiling_level(INTERNAL_FUNCTION_PARAMETERS, int get) { long level; zval *cmd, *cmd_return; zval **ok; mongo_db *db; if (get) { if (zend_parse_parameters_none() == FAILURE) { return; } level = -1; } else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &level) == FAILURE) { return; } } PHP_MONGO_GET_DB(getThis()); MAKE_STD_ZVAL(cmd); array_init(cmd); add_assoc_long(cmd, "profile", level); cmd_return = php_mongo_runcommand(db->link, &db->read_pref, Z_STRVAL_P(db->name), Z_STRLEN_P(db->name), cmd, NULL, 0, NULL TSRMLS_CC); zval_ptr_dtor(&cmd); if (!cmd_return) { return; } if ( zend_hash_find(HASH_P(cmd_return), "ok", 3, (void**)&ok) == SUCCESS && ((Z_TYPE_PP(ok) == IS_BOOL && Z_BVAL_PP(ok)) || Z_DVAL_PP(ok) == 1) ) { zend_hash_find(HASH_P(cmd_return), "was", 4, (void**)&ok); RETVAL_ZVAL(*ok, 1, 0); } else { RETVAL_NULL(); } zval_ptr_dtor(&cmd_return); }
PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */ { php_json_parser parser; php_json_parser_init(&parser, return_value, str, str_len, (int)options, (int)depth); if (php_json_yyparse(&parser)) { php_json_error_code error_code = php_json_parser_error_code(&parser); if (!(options & PHP_JSON_THROW_ON_ERROR)) { JSON_G(error_code) = error_code; } else { zend_throw_exception(php_json_exception_ce, php_json_get_error_msg(error_code), error_code); } RETVAL_NULL(); return FAILURE; } return SUCCESS; }
/* {{{ proto void Runkit_Sandbox_Parent::die(mixed message) MALIAS(exit) PATRICIDE!!!!!!!! */ PHP_METHOD(Runkit_Sandbox_Parent,die) { php_runkit_sandbox_parent_object *objval; zval *message = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &message) == FAILURE) { RETURN_FALSE; } RETVAL_NULL(); if (message && Z_TYPE_P(message) != IS_LONG) { convert_to_string(message); } PHP_RUNKIT_SANDBOX_PARENT_FETCHBOX_VERIFY_ACCESS(objval, this_ptr); if (!objval->self->parent_die) { php_error_docref(NULL, E_WARNING, "Patricide is disabled. Shame on you Oedipus."); /* Sent as a warning, but we'll really implement it as an E_ERROR */ objval->self->active = 0; RETURN_FALSE; } CG(unclean_shutdown) = 1; CG(in_compilation) = EG(in_execution) = 0; EG(current_execute_data) = NULL; PHP_RUNKIT_SANDBOX_PARENT_BEGIN(objval) if (message) { if (Z_TYPE_P(message) == IS_LONG) { EG(exit_status) = Z_LVAL_P(message); } else { PHPWRITE(Z_STRVAL_P(message), Z_STRLEN_P(message)); } } zend_bailout(); /* More of a murder-suicide really... */ PHP_RUNKIT_SANDBOX_PARENT_END(objval) }
/** * Check whether we have received valid parameters * * If this function returns false a warning will have been * generated and the return value has been set to NULL. * * @param return_value The return value to set on failure */ bool ZendCallable::valid(int provided, struct _zval_struct *return_value) { // we need the tsrm_ls variable TSRMLS_FETCH(); // how many parameters do we need as a bare minimum? int required = EG(current_execute_data)->function_state.function->common.required_num_args; // if we have the required minimum number of arguments there is no problem if (provided >= required) return true; // retrieve the function name to display the error auto *name = get_active_function_name(TSRMLS_C); // we do not have enough input parameters, show a warning about this Php::warning << name << "() expects at least " << required << " parameter(s), " << provided << " given" << std::flush; // set the return value to NULL RETVAL_NULL(); // we are not in a valid state return false; }
static PHP_METHOD(midgard_connection, set_loglevel) { RETVAL_NULL(); MidgardConnection *mgd =__midgard_connection_get_ptr(getThis()); CHECK_MGD(mgd); char *level; int level_length; zval *callback; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &level, &level_length, &callback) == FAILURE) return; /* no support for callback atm */ gboolean rv = midgard_connection_set_loglevel(mgd, (gchar *)level, php_midgard_log_errors); global_loghandler = midgard_connection_get_loghandler(mgd); if (MGDG(midgard_memory_debug)) { php_printf("---> global_loghandler = %d\n", global_loghandler); } RETURN_BOOL(rv); }
/* {{{ php_runkit_sandbox_parent_include_or_eval What's the point of running in a sandbox if you can leave whenever you want to??? */ static void php_runkit_sandbox_parent_include_or_eval(INTERNAL_FUNCTION_PARAMETERS, int type, int once) { php_runkit_sandbox_parent_object *objval; zval *zcode; int bailed_out = 0; zval *retval = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcode) == FAILURE) { RETURN_FALSE; } convert_to_string(zcode); PHP_RUNKIT_SANDBOX_PARENT_FETCHBOX_VERIFY_ACCESS(objval, this_ptr); if (type == ZEND_EVAL && !objval->self->parent_eval) { php_error_docref(NULL, E_WARNING, "Access to eval() code in the parent context is not enabled"); RETURN_FALSE; } if (type != ZEND_EVAL && !objval->self->parent_include) { php_error_docref(NULL, E_WARNING, "Access to include()/include_once()/require()/require_once() in the parent context is not enabled"); RETURN_FALSE; } RETVAL_NULL(); PHP_RUNKIT_SANDBOX_PARENT_BEGIN(objval) zend_op_array *op_array = NULL; int already_included = 0; op_array = php_runkit_sandbox_include_or_eval_int(return_value, zcode, type, once, &already_included); if (op_array) { HashTable *old_symbol_table = EG(active_symbol_table); zval **orig_retvalpp = EG(return_value_ptr_ptr); zend_op_array *orig_act_oparray = EG(active_op_array); EG(return_value_ptr_ptr) = &retval; EG(active_op_array) = op_array; EG(active_symbol_table) = php_runkit_sandbox_parent_resolve_symbol_table(objval); zend_execute(op_array); if (retval) { *return_value = *retval; } else { RETVAL_TRUE; } destroy_op_array(op_array); efree(op_array); EG(return_value_ptr_ptr) = orig_retvalpp; EG(active_op_array) = orig_act_oparray; EG(active_symbol_table) = old_symbol_table; } else if ((type != ZEND_INCLUDE) && !already_included) { /* include can fail to parse peacefully, * require and eval should die on failure */ bailed_out = 1; } PHP_RUNKIT_SANDBOX_PARENT_END(objval) if (bailed_out) { CG(unclean_shutdown) = 1; CG(in_compilation) = EG(in_execution) = 0; EG(current_execute_data) = NULL; PHP_RUNKIT_SANDBOX_PARENT_BEGIN(objval) zend_bailout(); PHP_RUNKIT_SANDBOX_PARENT_END(objval) } PHP_SANDBOX_CROSS_SCOPE_ZVAL_COPY_CTOR(return_value); /* Don't confuse the memory manager */ if (retval) { PHP_RUNKIT_SANDBOX_PARENT_BEGIN(objval) zval_ptr_dtor(&retval); PHP_RUNKIT_SANDBOX_PARENT_END(objval) } }
static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ { zval *id, retval, *context = NULL; xmlXPathContextPtr ctxp; xmlNodePtr nodep = NULL; xmlXPathObjectPtr xpathobjp; size_t expr_len, nsnbr = 0, xpath_type; dom_xpath_object *intern; dom_object *nodeobj; char *expr; xmlDoc *docp = NULL; xmlNsPtr *ns = NULL; zend_bool register_node_ns = 1; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|O!b", &id, dom_xpath_class_entry, &expr, &expr_len, &context, dom_node_class_entry, ®ister_node_ns) == FAILURE) { return; } intern = Z_XPATHOBJ_P(id); ctxp = (xmlXPathContextPtr) intern->dom.ptr; if (ctxp == NULL) { php_error_docref(NULL, E_WARNING, "Invalid XPath Context"); RETURN_FALSE; } docp = (xmlDocPtr) ctxp->doc; if (docp == NULL) { php_error_docref(NULL, E_WARNING, "Invalid XPath Document Pointer"); RETURN_FALSE; } if (context != NULL) { DOM_GET_OBJ(nodep, context, xmlNodePtr, nodeobj); } if (!nodep) { nodep = xmlDocGetRootElement(docp); } if (nodep && docp != nodep->doc) { php_error_docref(NULL, E_WARNING, "Node From Wrong Document"); RETURN_FALSE; } ctxp->node = nodep; if (register_node_ns) { /* Register namespaces in the node */ ns = xmlGetNsList(docp, nodep); if (ns != NULL) { while (ns[nsnbr] != NULL) nsnbr++; } } ctxp->namespaces = ns; ctxp->nsNr = nsnbr; xpathobjp = xmlXPathEvalExpression((xmlChar *) expr, ctxp); ctxp->node = NULL; if (ns != NULL) { xmlFree(ns); ctxp->namespaces = NULL; ctxp->nsNr = 0; } if (! xpathobjp) { RETURN_FALSE; } if (type == PHP_DOM_XPATH_QUERY) { xpath_type = XPATH_NODESET; } else { xpath_type = xpathobjp->type; } switch (xpath_type) { case XPATH_NODESET: { int i; xmlNodeSetPtr nodesetp; array_init(&retval); if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval)) { for (i = 0; i < nodesetp->nodeNr; i++) { xmlNodePtr node = nodesetp->nodeTab[i]; zval child; if (node->type == XML_NAMESPACE_DECL) { xmlNsPtr curns; xmlNodePtr nsparent; nsparent = node->_private; curns = xmlNewNs(NULL, node->name, NULL); if (node->children) { curns->prefix = xmlStrdup((xmlChar *) node->children); } if (node->children) { node = xmlNewDocNode(docp, NULL, (xmlChar *) node->children, node->name); } else { node = xmlNewDocNode(docp, NULL, (xmlChar *) "xmlns", node->name); } node->type = XML_NAMESPACE_DECL; node->parent = nsparent; node->ns = curns; } php_dom_create_object(node, &child, &intern->dom); add_next_index_zval(&retval, &child); } } php_dom_create_interator(return_value, DOM_NODELIST); nodeobj = Z_DOMOBJ_P(return_value); dom_xpath_iter(&retval, nodeobj); break; } case XPATH_BOOLEAN: RETVAL_BOOL(xpathobjp->boolval); break; case XPATH_NUMBER: RETVAL_DOUBLE(xpathobjp->floatval) break; case XPATH_STRING: RETVAL_STRING((char *) xpathobjp->stringval); break; default: RETVAL_NULL(); break; } xmlXPathFreeObject(xpathobjp); }
/* {{{ */ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { char* locale; int locale_len = 0; zval* object; long date_type = 0; long time_type = 0; long calendar = UCAL_GREGORIAN; char* timezone_str = NULL; int timezone_str_len = 0; char* pattern_str = NULL; int pattern_str_len = 0; UChar* svalue = NULL; /* UTF-16 pattern_str */ int slength = 0; UChar* timezone_utf16 = NULL; /* UTF-16 timezone_str */ int timezone_utf16_len = 0; UCalendar ucal_obj = NULL; IntlDateFormatter_object* dfo; intl_error_reset( NULL TSRMLS_CC ); object = return_value; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sll|sls", &locale, &locale_len, &date_type, &time_type, &timezone_str, &timezone_str_len, &calendar,&pattern_str, &pattern_str_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: unable to parse input parameters", 0 TSRMLS_CC ); zval_dtor(return_value); RETURN_NULL(); } INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); if (calendar != UCAL_TRADITIONAL && calendar != UCAL_GREGORIAN) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " "invalid value for calendar type; it must be one of " "IntlDateFormatter::TRADITIONAL (locale's default calendar) " "or IntlDateFormatter::GREGORIAN", 0 TSRMLS_CC); goto error; } DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; if (DATE_FORMAT_OBJECT(dfo) != NULL) { intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: cannot call constructor twice", 0 TSRMLS_CC); return; } /* Convert pattern (if specified) to UTF-16. */ if( pattern_str && pattern_str_len>0 ){ intl_convert_utf8_to_utf16(&svalue, &slength, pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { /* object construction -> only set global error */ intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " "error converting pattern to UTF-16", 0 TSRMLS_CC); goto error; } } /* resources allocated from now on */ /* Convert pattern (if specified) to UTF-16. */ if( timezone_str && timezone_str_len >0 ){ intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_str, timezone_str_len, &INTL_DATA_ERROR_CODE(dfo)); if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " "error converting timezone_str to UTF-16", 0 TSRMLS_CC); goto error; } } if(locale_len == 0) { locale = INTL_G(default_locale); } if( pattern_str && pattern_str_len>0 ){ DATE_FORMAT_OBJECT(dfo) = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, timezone_utf16, timezone_utf16_len, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); } else { DATE_FORMAT_OBJECT(dfo) = udat_open(time_type, date_type, locale, timezone_utf16, timezone_utf16_len, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); } if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { if (calendar != UCAL_TRADITIONAL) { ucal_obj = ucal_open(timezone_utf16, timezone_utf16_len, locale, calendar, &INTL_DATA_ERROR_CODE(dfo)); if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { udat_setCalendar(DATE_FORMAT_OBJECT(dfo), ucal_obj); ucal_close(ucal_obj); } else { intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create" ": error opening calendar", 0 TSRMLS_CC); goto error; } } } else { intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " "formatter creation failed", 0 TSRMLS_CC); goto error; } /* Set the class variables */ dfo->date_type = date_type; dfo->time_type = time_type; dfo->calendar = calendar; if( timezone_str && timezone_str_len > 0){ dfo->timezone_id = estrndup( timezone_str, timezone_str_len); } error: if (svalue) { efree(svalue); } if (timezone_utf16) { efree(timezone_utf16); } if (U_FAILURE(intl_error_get_code(NULL TSRMLS_CC))) { /* free_object handles partially constructed instances fine */ zval_dtor(return_value); RETVAL_NULL(); } }
static void _php_intlgregcal_constructor_body( INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { zval *tz_object = NULL; zval args_a[6] = {0}, *args = &args_a[0]; char *locale = NULL; size_t locale_len; zend_long largs[6]; UErrorCode status = U_ZERO_ERROR; int variant; int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; intl_error_reset(NULL); // parameter number validation / variant determination if (ZEND_NUM_ARGS() > 6 || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: too many arguments", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } for (variant = ZEND_NUM_ARGS(); variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL; variant--) {} if (variant == 4) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: no variant with 4 arguments " "(excluding trailing NULLs)", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } // argument parsing if (variant <= 2) { if (zend_parse_parameters_ex(zpp_flags, MIN(ZEND_NUM_ARGS(), 2), "|z!s!", &tz_object, &locale, &locale_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: bad arguments", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } } if (variant > 2 && zend_parse_parameters_ex(zpp_flags, ZEND_NUM_ARGS(), "lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4], &largs[5]) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: bad arguments", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } // instantion of ICU object GregorianCalendar *gcal = NULL; if (variant <= 2) { // From timezone and locale (0 to 2 arguments) TimeZone *tz = timezone_process_timezone_argument(tz_object, NULL, "intlgregcal_create_instance"); if (tz == NULL) { if (!EG(exception)) { zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); } if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } if (!locale) { locale = const_cast<char*>(intl_locale_get_default()); } gcal = new GregorianCalendar(tz, Locale::createFromName(locale), status); if (U_FAILURE(status)) { intl_error_set(NULL, status, "intlgregcal_create_instance: error " "creating ICU GregorianCalendar from time zone and locale", 0); if (gcal) { delete gcal; } delete tz; if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } } else { // From date/time (3, 5 or 6 arguments) for (int i = 0; i < variant; i++) { if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: at least one of the arguments" " has an absolute value that is too large", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } } if (variant == 3) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], status); } else if (variant == 5) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], status); } else if (variant == 6) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], (int32_t)largs[5], status); } if (U_FAILURE(status)) { intl_error_set(NULL, status, "intlgregcal_create_instance: error " "creating ICU GregorianCalendar from date", 0); if (gcal) { delete gcal; } if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } timelib_tzinfo *tzinfo = get_timezone_info(); #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 42 UnicodeString tzstr = UnicodeString::fromUTF8(StringPiece(tzinfo->name)); #else UnicodeString tzstr = UnicodeString(tzinfo->name, strlen(tzinfo->name), US_INV); #endif if (tzstr.isBogus()) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: could not create UTF-8 string " "from PHP's default timezone name (see date_default_timezone_get())", 0); delete gcal; if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } TimeZone *tz = TimeZone::createTimeZone(tzstr); gcal->adoptTimeZone(tz); } Calendar_object *co = Z_INTL_CALENDAR_P(return_value); co->ucal = gcal; }
void orbit_class_function_call( zend_class_entry * pClass, int dataType, zend_property_reference *pPropertyReference, Class_Constructor pConstructor, Class_CallFunction pCallFunction, INTERNAL_FUNCTION_PARAMETERS) { /* get object */ zval * object = pPropertyReference->object; /* get function name */ zend_overloaded_element * function_name = (zend_overloaded_element *)pPropertyReference->elements_list->tail->data; /* handle parameters */ zval ** arguments = orbit_new_n(zval *, ZEND_NUM_ARGS()); /*(zval **)emalloc(sizeof(zval *) * ZEND_NUM_ARGS());*/ if (getParametersArray(ht, ZEND_NUM_ARGS(), arguments) == FAILURE) { /* TODO: handle error */ } /* constructor or normal function? */ if (zend_llist_count(pPropertyReference->elements_list) == 1 && !strcasecmp(function_name->element.value.str.val, pClass->name)) { /* constructor */ if (pConstructor) { void * p_data = NULL; zend_bool success = (*pConstructor)(&p_data, ZEND_NUM_ARGS(), arguments); if (success) orbit_save_data(object, dataType, p_data); } else { zend_error(E_WARNING, "(Satellite) This class has no constructor"); \ } } else { /* normal function */ if (pCallFunction) { void * p_data = orbit_retrieve_data(object, dataType); if (p_data == NULL) { /* * this means that the constructor has failed earlier! * -- or should NULL be allowed here? */ php_error(E_WARNING, "(Satellite) Class has no data!"); RETVAL_NULL(); goto orbit_class_function_call_exit; } /* pval * return_value is a part of INTERNAL_FUNCTION_PARAMETERS */ (*pCallFunction)(p_data, function_name->element.value.str.val, ZEND_NUM_ARGS(), arguments, return_value); } else { zend_error(E_WARNING, "(Satellite) Can't call functions in this class"); \ } } orbit_class_function_call_exit: satellite_delete(arguments); /* seems to be required! */ zval_dtor(&function_name->element); }
/** * Yield (return) the given value * * @param return_value The return_value to set * @param value The value to return to PHP */ void ZendCallable::yield(struct _zval_struct *return_value, std::nullptr_t value) { // set the return value to null RETVAL_NULL(); }