PHPAPI void php_info_print_table_start() { php_printf("<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 WIDTH=600 BGCOLOR=\"#000000\" ALIGN=\"CENTER\">\n"); }
int shurrik_hash_apply_for_array(zval **val,int num_args,va_list args,zend_hash_key *hash_key) { TSRMLS_FETCH(); php_printf(" "); if (hash_key->nKeyLength) { //如果是字符串类型的key PHPWRITE(hash_key->arKey, hash_key->nKeyLength); } else { //如果是数字类型的key php_printf("%ld", hash_key->h); } php_printf("=>"); if(Z_TYPE_PP(val) == IS_ARRAY){ //php_printf("%d",(**tmp).type); //zend_hash_apply((**val).value.ht,shurrik_hash_apply_for_zval, 0); /*if(Z_TYPE_PP(tmp) == IS_STRING){ php_printf("%s",(**tmp).value.str.val); }*/ Bucket *p; zval **tmp; p = (**val).value.ht->pListHead; if(p == NULL){ return ZEND_HASH_APPLY_STOP; } php_printf("array(\n"); while (p != NULL) { php_printf(" "); tmp = p->pData; if(p->nKeyLength){ php_printf("%s=>",p->arKey); }else { php_printf("%ld=>",p->h); } if(Z_TYPE_PP(tmp) == IS_STRING){ php_printf("%s\n",(**tmp).value.str.val); } if(Z_TYPE_PP(tmp) == IS_ARRAY){ //php_printf("array()\n"); //shurrik_apply_array(tmp); //zend_hash_apply_with_arguments(((**tmp).value.ht)->pListHead->pData,shurrik_hash_apply_for_array, 0); //shurrik_hash_apply(tmp,p); //return shurrik_hash_apply_for_zval(tmp TSRMLS_CC); } p = p->pListNext; } php_printf(" );\n"); } if(Z_TYPE_PP(val) == IS_STRING){ php_printf("%s",(**val).value.str.val); } php_printf("\n"); //返回,继续遍历下一个~ return ZEND_HASH_APPLY_KEEP; }
PHP_METHOD(Test_Echoes, testEcho1) { php_printf("%d", 1); }
PHP_METHOD(Test_Echoes, testEcho4) { php_printf("%s", 0 ? "1": ""); }
PHP_METHOD(Test_RegexDNA, process) { HashTable *_5; HashPosition _4; int ZEPHIR_LAST_CALL_STATUS; zephir_nts_static zephir_fcall_cache_entry *_3 = NULL, *_8 = NULL; zval *path, *variants, *vIUB, *vIUBnew, *stuffToRemove, *contents = NULL, *initialLength, *regex = NULL, *codeLength, *discard = NULL, *_0 = NULL, *_1, *_2 = NULL, **_6, *_7 = NULL, *_9 = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &path); ZEPHIR_INIT_VAR(discard); ZVAL_NULL(discard); ZEPHIR_INIT_VAR(variants); array_init_size(variants, 13); ZEPHIR_INIT_VAR(_0); ZVAL_STRING(_0, "agggtaaa|tttaccct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "[cgt]gggtaaa|tttaccc[acg]", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "a[act]ggtaaa|tttacc[agt]t", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "ag[act]gtaaa|tttac[agt]ct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "agg[act]taaa|ttta[agt]cct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "aggg[acg]aaa|ttt[cgt]ccct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "agggt[cgt]aa|tt[acg]accct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "agggta[cgt]a|t[acg]taccct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "agggtaa[cgt]|[acg]ttaccct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_VAR(vIUB); array_init(vIUB); ZEPHIR_INIT_VAR(vIUBnew); array_init(vIUBnew); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/B/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 30); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(c|g|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 30); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/D/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 31); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(a|g|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 31); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/H/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 32); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(a|c|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 32); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/K/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 33); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(g|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 33); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/M/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 34); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(a|c)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 34); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/N/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 35); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(a|c|g|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 35); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/R/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 36); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(a|g)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 36); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/S/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 37); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(c|g)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 37); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/V/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 38); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(a|c|g)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 38); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/W/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 39); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(a|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 39); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "/Y/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE, "test/regexdna.zep", 40); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "(c|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE, "test/regexdna.zep", 40); ZEPHIR_INIT_VAR(stuffToRemove); ZVAL_STRING(stuffToRemove, "^>.*$|\n", 1); ZEPHIR_INIT_NVAR(discard); ZVAL_NULL(discard); ZEPHIR_INIT_VAR(contents); zephir_file_get_contents(contents, path TSRMLS_CC); ZEPHIR_INIT_VAR(initialLength); ZVAL_LONG(initialLength, zephir_fast_strlen_ev(contents)); ZEPHIR_INIT_VAR(_1); ZEPHIR_CONCAT_SVS(_1, "/", stuffToRemove, "/mS"); ZEPHIR_INIT_NVAR(_0); ZVAL_STRING(_0, "", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_FUNCTION(&_2, "preg_replace", &_3, _1, _0, contents); zephir_check_temp_parameter(_0); zephir_check_call_status(); ZEPHIR_CPY_WRT(contents, _2); ZEPHIR_INIT_VAR(codeLength); ZVAL_LONG(codeLength, zephir_fast_strlen_ev(contents)); zephir_is_iterable(variants, &_5, &_4, 0, 0, "test/regexdna.zep", 59); for ( ; zephir_hash_get_current_data_ex(_5, (void**) &_6, &_4) == SUCCESS ; zephir_hash_move_forward_ex(_5, &_4) ) { ZEPHIR_GET_HVALUE(regex, _6); zend_print_zval(regex, 0); php_printf("%s", " "); ZEPHIR_INIT_LNVAR(_7); ZEPHIR_CONCAT_SVS(_7, "/", regex, "/iS"); Z_SET_ISREF_P(discard); ZEPHIR_CALL_FUNCTION(&_2, "preg_match_all", &_8, _7, contents, discard); Z_UNSET_ISREF_P(discard); zephir_check_call_status(); zend_print_zval(_2, 0); php_printf("%c", '\n'); } ZEPHIR_CALL_FUNCTION(&_9, "preg_replace", &_3, vIUB, vIUBnew, contents); zephir_check_call_status(); ZEPHIR_CPY_WRT(contents, _9); php_printf("%c", '\n'); zend_print_zval(initialLength, 0); php_printf("%c", '\n'); zend_print_zval(codeLength, 0); php_printf("%c", '\n'); php_printf("%d", zephir_fast_strlen_ev(contents)); php_printf("%c", '\n'); ZEPHIR_MM_RESTORE(); }
PHPAPI void php_var_dump(zval *struc, int level TSRMLS_DC) /* {{{ */ { HashTable *myht; zend_string *class_name; int is_temp; int is_ref = 0; zend_ulong num; zend_string *key; zval *val; if (level > 1) { php_printf("%*c", level - 1, ' '); } again: switch (Z_TYPE_P(struc)) { case IS_FALSE: php_printf("%sbool(false)\n", COMMON); break; case IS_TRUE: php_printf("%sbool(true)\n", COMMON); break; case IS_NULL: php_printf("%sNULL\n", COMMON); break; case IS_LONG: php_printf("%sint(" ZEND_LONG_FMT ")\n", COMMON, Z_LVAL_P(struc)); break; case IS_DOUBLE: php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_P(struc)); break; case IS_STRING: php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_P(struc)); PHPWRITE(Z_STRVAL_P(struc), Z_STRLEN_P(struc)); PUTS("\"\n"); break; case IS_ARRAY: myht = Z_ARRVAL_P(struc); if (level > 1 && ZEND_HASH_APPLY_PROTECTION(myht) && ++myht->u.v.nApplyCount > 1) { PUTS("*RECURSION*\n"); --myht->u.v.nApplyCount; return; } php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht)); is_temp = 0; ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { php_array_element_dump(val, num, key, level TSRMLS_CC); } ZEND_HASH_FOREACH_END(); if (level > 1 && ZEND_HASH_APPLY_PROTECTION(myht)) { --myht->u.v.nApplyCount; } if (is_temp) { zend_hash_destroy(myht); efree(myht); } if (level > 1) { php_printf("%*c", level-1, ' '); } PUTS("}\n"); break; case IS_OBJECT: myht = Z_OBJDEBUG_P(struc, is_temp); if (myht && ++myht->u.v.nApplyCount > 1) { PUTS("*RECURSION*\n"); --myht->u.v.nApplyCount; return; } class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc) TSRMLS_CC); php_printf("%sobject(%s)#%d (%d) {\n", COMMON, class_name->val, Z_OBJ_HANDLE_P(struc), myht ? zend_obj_num_elements(myht) : 0); zend_string_release(class_name); if (myht) { zend_ulong num; zend_string *key; zval *val; ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { php_object_property_dump(val, num, key, level TSRMLS_CC); } ZEND_HASH_FOREACH_END(); --myht->u.v.nApplyCount; if (is_temp) { zend_hash_destroy(myht); efree(myht); } }
//定义普通类的方法:ZEND_METHOD,注意区别上面那个叫ZEND_FUNCTION ZEND_METHOD( myclass , public_method ) { php_printf("我是public类型的方法\n"); }
static int do_cli(int argc, char **argv) /* {{{ */ { int c; zend_file_handle file_handle; int behavior = PHP_MODE_STANDARD; char *reflection_what = NULL; volatile int request_started = 0; volatile int exit_status = 0; char *php_optarg = NULL, *orig_optarg = NULL; int php_optind = 1, orig_optind = 1; char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL; char *arg_free=NULL, **arg_excp=&arg_free; char *script_file=NULL, *translated_path = NULL; int interactive=0; int lineno = 0; const char *param_error=NULL; int hide_argv = 0; zend_try { CG(in_compilation) = 0; /* not initialized but needed for several options */ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (c) { case 'i': /* php info & quit */ if (php_request_startup()==FAILURE) { goto err; } request_started = 1; php_print_info(0xFFFFFFFF); php_output_end_all(); exit_status = (c == '?' && argc > 1 && !strchr(argv[1], c)); goto out; case 'v': /* show php version & quit */ php_printf("PHP %s (%s) (built: %s %s) ( %s)\nCopyright (c) 1997-2016 The PHP Group\n%s", PHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__, #if ZTS "ZTS " #else "NTS " #endif #ifdef COMPILER COMPILER " " #endif #ifdef ARCHITECTURE ARCHITECTURE " " #endif #if ZEND_DEBUG "DEBUG " #endif #ifdef HAVE_GCOV "GCOV " #endif , get_zend_version() ); sapi_deactivate(); goto out; case 'm': /* list compiled in modules */ if (php_request_startup()==FAILURE) { goto err; } request_started = 1; php_printf("[PHP Modules]\n"); print_modules(); php_printf("\n[Zend Modules]\n"); print_extensions(); php_printf("\n"); php_output_end_all(); exit_status=0; goto out; default: break; } } /* Set some CLI defaults */ SG(options) |= SAPI_OPTION_NO_CHDIR; php_optind = orig_optind; php_optarg = orig_optarg; while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (c) { case 'a': /* interactive mode */ if (!interactive) { if (behavior != PHP_MODE_STANDARD) { param_error = param_mode_conflict; break; } interactive=1; } break; case 'C': /* don't chdir to the script directory */ /* This is default so NOP */ break; case 'F': if (behavior == PHP_MODE_PROCESS_STDIN) { if (exec_run || script_file) { param_error = "You can use -R or -F only once.\n"; break; } } else if (behavior != PHP_MODE_STANDARD) { param_error = param_mode_conflict; break; } behavior=PHP_MODE_PROCESS_STDIN; script_file = php_optarg; break; case 'f': /* parse file */ if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) { param_error = param_mode_conflict; break; } else if (script_file) { param_error = "You can use -f only once.\n"; break; } script_file = php_optarg; break; case 'l': /* syntax check mode */ if (behavior != PHP_MODE_STANDARD) { break; } behavior=PHP_MODE_LINT; break; case 'q': /* do not generate HTTP headers */ /* This is default so NOP */ break; case 'r': /* run code from command line */ if (behavior == PHP_MODE_CLI_DIRECT) { if (exec_direct || script_file) { param_error = "You can use -r only once.\n"; break; } } else if (behavior != PHP_MODE_STANDARD || interactive) { param_error = param_mode_conflict; break; } behavior=PHP_MODE_CLI_DIRECT; exec_direct=php_optarg; break; case 'R': if (behavior == PHP_MODE_PROCESS_STDIN) { if (exec_run || script_file) { param_error = "You can use -R or -F only once.\n"; break; } } else if (behavior != PHP_MODE_STANDARD) { param_error = param_mode_conflict; break; } behavior=PHP_MODE_PROCESS_STDIN; exec_run=php_optarg; break; case 'B': if (behavior == PHP_MODE_PROCESS_STDIN) { if (exec_begin) { param_error = "You can use -B only once.\n"; break; } } else if (behavior != PHP_MODE_STANDARD || interactive) { param_error = param_mode_conflict; break; } behavior=PHP_MODE_PROCESS_STDIN; exec_begin=php_optarg; break; case 'E': if (behavior == PHP_MODE_PROCESS_STDIN) { if (exec_end) { param_error = "You can use -E only once.\n"; break; } } else if (behavior != PHP_MODE_STANDARD || interactive) { param_error = param_mode_conflict; break; } behavior=PHP_MODE_PROCESS_STDIN; exec_end=php_optarg; break; case 's': /* generate highlighted HTML from source */ if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) { param_error = "Source highlighting only works for files.\n"; break; } behavior=PHP_MODE_HIGHLIGHT; break; case 'w': if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) { param_error = "Source stripping only works for files.\n"; break; } behavior=PHP_MODE_STRIP; break; case 'z': /* load extension file */ zend_load_extension(php_optarg); break; case 'H': hide_argv = 1; break; case 10: behavior=PHP_MODE_REFLECTION_FUNCTION; reflection_what = php_optarg; break; case 11: behavior=PHP_MODE_REFLECTION_CLASS; reflection_what = php_optarg; break; case 12: behavior=PHP_MODE_REFLECTION_EXTENSION; reflection_what = php_optarg; break; case 13: behavior=PHP_MODE_REFLECTION_ZEND_EXTENSION; reflection_what = php_optarg; break; case 14: behavior=PHP_MODE_REFLECTION_EXT_INFO; reflection_what = php_optarg; break; case 15: behavior = PHP_MODE_SHOW_INI_CONFIG; break; default: break; } } if (param_error) { PUTS(param_error); exit_status=1; goto err; } if (interactive) { #if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) printf("Interactive shell\n\n"); #else printf("Interactive mode enabled\n\n"); #endif fflush(stdout); } /* only set script_file if not set already and not in direct mode and not at end of parameter list */ if (argc > php_optind && !script_file && behavior!=PHP_MODE_CLI_DIRECT && behavior!=PHP_MODE_PROCESS_STDIN && strcmp(argv[php_optind-1],"--")) { script_file=argv[php_optind]; php_optind++; } if (script_file) { if (cli_seek_file_begin(&file_handle, script_file, &lineno) != SUCCESS) { goto err; } else { char real_path[MAXPATHLEN]; if (VCWD_REALPATH(script_file, real_path)) { translated_path = strdup(real_path); } script_filename = script_file; } } else { /* We could handle PHP_MODE_PROCESS_STDIN in a different manner */ /* here but this would make things only more complicated. And it */ /* is consitent with the way -R works where the stdin file handle*/ /* is also accessible. */ file_handle.filename = "-"; file_handle.handle.fp = stdin; } file_handle.type = ZEND_HANDLE_FP; file_handle.opened_path = NULL; file_handle.free_filename = 0; php_self = (char*)file_handle.filename; /* before registering argv to module exchange the *new* argv[0] */ /* we can achieve this without allocating more memory */ SG(request_info).argc=argc-php_optind+1; arg_excp = argv+php_optind-1; arg_free = argv[php_optind-1]; SG(request_info).path_translated = translated_path? translated_path: (char*)file_handle.filename; argv[php_optind-1] = (char*)file_handle.filename; SG(request_info).argv=argv+php_optind-1; if (php_request_startup()==FAILURE) { *arg_excp = arg_free; fclose(file_handle.handle.fp); PUTS("Could not startup.\n"); goto err; } request_started = 1; CG(start_lineno) = lineno; *arg_excp = arg_free; /* reconstuct argv */ if (hide_argv) { int i; for (i = 1; i < argc; i++) { memset(argv[i], 0, strlen(argv[i])); } } zend_is_auto_global_str(ZEND_STRL("_SERVER")); PG(during_request_startup) = 0; switch (behavior) { case PHP_MODE_STANDARD: if (strcmp(file_handle.filename, "-")) { cli_register_file_handles(); } if (interactive && cli_shell_callbacks.cli_shell_run) { exit_status = cli_shell_callbacks.cli_shell_run(); } else { php_execute_script(&file_handle); exit_status = EG(exit_status); } break; case PHP_MODE_LINT: exit_status = php_lint_script(&file_handle); if (exit_status==SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { zend_printf("Errors parsing %s\n", file_handle.filename); } break; case PHP_MODE_STRIP: if (open_file_for_scanning(&file_handle)==SUCCESS) { zend_strip(); } goto out; break; case PHP_MODE_HIGHLIGHT: { zend_syntax_highlighter_ini syntax_highlighter_ini; if (open_file_for_scanning(&file_handle)==SUCCESS) { php_get_highlight_struct(&syntax_highlighter_ini); zend_highlight(&syntax_highlighter_ini); } goto out; } break; case PHP_MODE_CLI_DIRECT: cli_register_file_handles(); if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1) == FAILURE) { exit_status=254; } break; case PHP_MODE_PROCESS_STDIN: { char *input; size_t len, index = 0; zval argn, argi; cli_register_file_handles(); if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1) == FAILURE) { exit_status=254; } while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) { len = strlen(input); while (len > 0 && len-- && (input[len]=='\n' || input[len]=='\r')) { input[len] = '\0'; } ZVAL_STRINGL(&argn, input, len + 1); zend_hash_str_update(&EG(symbol_table), "argn", sizeof("argn")-1, &argn); ZVAL_LONG(&argi, ++index); zend_hash_str_update(&EG(symbol_table), "argi", sizeof("argi")-1, &argi); if (exec_run) { if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1) == FAILURE) { exit_status=254; } } else { if (script_file) { if (cli_seek_file_begin(&file_handle, script_file, &lineno) != SUCCESS) { exit_status = 1; } else { CG(start_lineno) = lineno; php_execute_script(&file_handle); exit_status = EG(exit_status); } } } efree(input); } if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1) == FAILURE) { exit_status=254; } break; } case PHP_MODE_REFLECTION_FUNCTION: case PHP_MODE_REFLECTION_CLASS: case PHP_MODE_REFLECTION_EXTENSION: case PHP_MODE_REFLECTION_ZEND_EXTENSION: { zend_class_entry *pce = NULL; zval arg, ref; zend_execute_data execute_data; switch (behavior) { default: break; case PHP_MODE_REFLECTION_FUNCTION: if (strstr(reflection_what, "::")) { pce = reflection_method_ptr; } else { pce = reflection_function_ptr; } break; case PHP_MODE_REFLECTION_CLASS: pce = reflection_class_ptr; break; case PHP_MODE_REFLECTION_EXTENSION: pce = reflection_extension_ptr; break; case PHP_MODE_REFLECTION_ZEND_EXTENSION: pce = reflection_zend_extension_ptr; break; } ZVAL_STRING(&arg, reflection_what); object_init_ex(&ref, pce); memset(&execute_data, 0, sizeof(zend_execute_data)); EG(current_execute_data) = &execute_data; zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, &arg); if (EG(exception)) { zval tmp, *msg, rv; ZVAL_OBJ(&tmp, EG(exception)); msg = zend_read_property(zend_ce_exception, &tmp, "message", sizeof("message")-1, 0, &rv); zend_printf("Exception: %s\n", Z_STRVAL_P(msg)); zval_ptr_dtor(&tmp); EG(exception) = NULL; } else { zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, &ref); } zval_ptr_dtor(&ref); zval_ptr_dtor(&arg); break; } case PHP_MODE_REFLECTION_EXT_INFO: { int len = (int)strlen(reflection_what); char *lcname = zend_str_tolower_dup(reflection_what, len); zend_module_entry *module; if ((module = zend_hash_str_find_ptr(&module_registry, lcname, len)) == NULL) { if (!strcmp(reflection_what, "main")) { display_ini_entries(NULL); } else { zend_printf("Extension '%s' not present.\n", reflection_what); exit_status = 1; } } else { php_info_print_module(module); } efree(lcname); break; } case PHP_MODE_SHOW_INI_CONFIG: { zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH); zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)"); zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)"); zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)"); break; } } } zend_end_try(); out: if (request_started) { php_request_shutdown((void *) 0); } if (translated_path) { free(translated_path); } if (exit_status == 0) { exit_status = EG(exit_status); } return exit_status; err: sapi_deactivate(); zend_ini_deactivate(); exit_status = 1; goto out; }
PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) { php_printf("<TR BGCOLOR=\"" PHP_HEADER_COLOR "\"><TH COLSPAN=%d>%s</TH></TR>\n", num_cols, header ); }
void _php3_snmp(INTERNAL_FUNCTION_PARAMETERS, int st) { pval *a1, *a2, *a3; INT operation; LPSTR agent; LPSTR community; RFC1157VarBindList variableBindings; LPSNMP_MGR_SESSION session; INT timeout = TIMEOUT; INT retries = RETRIES; BYTE requestType; AsnInteger errorStatus; AsnInteger errorIndex; AsnObjectIdentifier oid; char *chkPtr = NULL; if (getParameters(ht, 3, &a1, &a2, &a3) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(a1); convert_to_string(a2); convert_to_string(a3); agent=a1->value.str.val; community=a2->value.str.val; operation=st; SnmpMgrStrToOid(a3->value.str.val, &oid); /* I've limited this to only one oid, but we can create a list of oid's here, and expand the function to take multiple oid's */ variableBindings.list->name = oid; variableBindings.list->value.asnType = ASN_NULL; variableBindings.len = 1; /* Establish a SNMP session to communicate with the remote agent. The community, communications timeout, and communications retry count for the session are also required. */ if ((session = SnmpMgrOpen(agent, community, timeout, retries)) == NULL){ php_error(E_WARNING,"error on SnmpMgrOpen %d\n", GetLastError()); } /* Determine and perform the requested operation.*/ if (operation == GET || operation == GETNEXT){ /* Get and GetNext are relatively simple operations to perform. Simply initiate the request and process the result and/or possible error conditions. */ if (operation == GET){ requestType = ASN_RFC1157_GETREQUEST; } else { requestType = ASN_RFC1157_GETNEXTREQUEST; } /* Request that the API carry out the desired operation.*/ if (!SnmpMgrRequest(session, requestType, &variableBindings, &errorStatus, &errorIndex)){ /* The API is indicating an error. */ php_error(E_WARNING,"error on SnmpMgrRequest %d\n", GetLastError()); } else { /* The API succeeded, errors may be indicated from the remote agent. */ if (errorStatus > 0){ php_error(E_WARNING,"Error: errorStatus=%d, errorIndex=%d\n", errorStatus, errorIndex); } else { /* Display the resulting variable bindings.*/ UINT i; char *str = NULL; for(i=0; i < variableBindings.len; i++) { SnmpMgrOidToStr(&variableBindings.list[i].name, &str); php_printf("Variable = %s\n", str); if (str) SNMP_free(str); php_printf("Value = "); SnmpUtilPrintAsnAny(&variableBindings.list[i].value); php_printf("\n"); } /* end for() */ } } /* Free the variable bindings that have been allocated.*/ SnmpUtilVarBindListFree(&variableBindings); } else if (operation == WALK) { /* Walk is a common term used to indicate that all MIB variables under a given OID are to be traversed and displayed. This is a more complex operation requiring tests and looping in addition to the steps for get/getnext above. */ AsnObjectIdentifier root; AsnObjectIdentifier tempOid; SnmpUtilOidCpy(&root, &variableBindings.list[0].name); requestType = ASN_RFC1157_GETNEXTREQUEST; while(1) { if (!SnmpMgrRequest(session, requestType, &variableBindings, &errorStatus, &errorIndex)){ /* The API is indicating an error.*/ php_error(E_WARNING,"error on SnmpMgrRequest %d\n", GetLastError()); break; } else { /* The API succeeded, errors may be indicated from the remote agent. Test for end of subtree or end of MIB. */ if (errorStatus == SNMP_ERRORSTATUS_NOSUCHNAME || SnmpUtilOidNCmp(&variableBindings.list[0].name, &root, root.idLength)) { PUTS("End of MIB subtree.\n\n"); break; } /* Test for general error conditions or sucesss. */ if (errorStatus > 0){ php_error(E_ERROR,"Error: errorStatus=%d, errorIndex=%d \n", errorStatus, errorIndex); break; } else { /* Display resulting variable binding for this iteration. */ char *str = NULL; SnmpMgrOidToStr(&variableBindings.list[0].name, &str); php_printf("Variable = %s\n", str); if (str) SNMP_free(str); php_printf("Value = "); SnmpUtilPrintAsnAny(&variableBindings.list[0].value); php_printf("\n"); } } /* end if () */ /* Prepare for the next iteration. Make sure returned oid is preserved and the returned value is freed. */ SnmpUtilOidCpy(&tempOid, &variableBindings.list[0].name); SnmpUtilVarBindFree(&variableBindings.list[0]); SnmpUtilOidCpy(&variableBindings.list[0].name, &tempOid); variableBindings.list[0].value.asnType = ASN_NULL; SnmpUtilOidFree(&tempOid); } /* end while() */ /* Free the variable bindings that have been allocated.*/ SnmpUtilVarBindListFree(&variableBindings); SnmpUtilOidFree(&root); } /* end if (operation) */ /* Close SNMP session with the remote agent.*/ if (!SnmpMgrClose(session)){ php_error(E_WARNING,"error on SnmpMgrClose %d\n", GetLastError()); } }
PHPAPI void php_info_print_hr() { php_printf("<HR NOSHADE SIZE=1 WIDTH=600>\n"); }
PHPAPI void php_info_print_box_end() { php_printf("</TD></TR>\n"); php_info_print_table_end(); }
PHPAPI void php_info_print_table_end() { php_printf("</TABLE><BR>\n"); }
static int print_module_info(zval *element) /* {{{ */ { zend_module_entry *module = (zend_module_entry*)Z_PTR_P(element); php_printf("%s\n", module->name); return ZEND_HASH_APPLY_KEEP; }
ZEND_METHOD( myclass , __construct ) { php_printf("我是__construct方法\n"); }
static int print_extension_info(zend_extension *ext, void *arg) /* {{{ */ { php_printf("%s\n", ext->name); return ZEND_HASH_APPLY_KEEP; }
//父类的hello方法 ZEND_METHOD(parent_class,hello) { php_printf("hello world!\n"); }
PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ { HashTable *myht; zend_string *class_name; int is_temp; int is_ref = 0; zend_ulong num; zend_string *key; zval *val; uint32_t count; if (level > 1) { php_printf("%*c", level - 1, ' '); } again: switch (Z_TYPE_P(struc)) { case IS_FALSE: php_printf("%sbool(false)\n", COMMON); break; case IS_TRUE: php_printf("%sbool(true)\n", COMMON); break; case IS_NULL: php_printf("%sNULL\n", COMMON); break; case IS_LONG: php_printf("%sint(" ZEND_LONG_FMT ")\n", COMMON, Z_LVAL_P(struc)); break; case IS_DOUBLE: php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_P(struc)); break; case IS_STRING: php_printf("%sstring(%zd) \"", COMMON, Z_STRLEN_P(struc)); PHPWRITE(Z_STRVAL_P(struc), Z_STRLEN_P(struc)); PUTS("\"\n"); break; case IS_ARRAY: myht = Z_ARRVAL_P(struc); if (level > 1 && !(GC_FLAGS(myht) & GC_IMMUTABLE)) { if (GC_IS_RECURSIVE(myht)) { PUTS("*RECURSION*\n"); return; } GC_PROTECT_RECURSION(myht); } count = zend_array_count(myht); php_printf("%sarray(%d) {\n", COMMON, count); ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { php_array_element_dump(val, num, key, level); } ZEND_HASH_FOREACH_END(); if (level > 1 && !(GC_FLAGS(myht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(myht); } if (level > 1) { php_printf("%*c", level-1, ' '); } PUTS("}\n"); break; case IS_OBJECT: if (Z_IS_RECURSIVE_P(struc)) { PUTS("*RECURSION*\n"); return; } Z_PROTECT_RECURSION_P(struc); myht = Z_OBJDEBUG_P(struc, is_temp); class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc)); php_printf("%sobject(%s)#%d (%d) {\n", COMMON, ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), myht ? zend_array_count(myht) : 0); zend_string_release(class_name); if (myht) { zend_ulong num; zend_string *key; zval *val; ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { php_object_property_dump(val, num, key, level); } ZEND_HASH_FOREACH_END(); if (is_temp) { zend_hash_destroy(myht); efree(myht); } }
ZEND_METHOD(myclass,public_method) { php_printf("this is pulic method to be called!"); }
static int cli_main( int argc, char * argv[] ) { static const char * ini_defaults[] = { "report_zend_debug", "0", "display_errors", "1", "register_argc_argv", "1", "html_errors", "0", "implicit_flush", "1", "output_buffering", "0", "max_execution_time", "0", "max_input_time", "-1", NULL }; const char ** ini; char ** p = &argv[1]; char ** argend= &argv[argc]; int ret = -1; int c; #if PHP_MAJOR_VERSION >= 7 zend_string * psKey; #endif lsapi_mode = 0; /* enter CLI mode */ #ifdef PHP_WIN32 _fmode = _O_BINARY; /*sets default for file streams to binary */ setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ #endif zend_first_try { SG(server_context) = (void *) 1; zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */ CG(in_compilation) = 0; /* not initialized but needed for several options */ SG(options) |= SAPI_OPTION_NO_CHDIR; #if PHP_MAJOR_VERSION < 7 EG(uninitialized_zval_ptr) = NULL; #endif for( ini = ini_defaults; *ini; ini+=2 ) { #if PHP_MAJOR_VERSION >= 7 psKey = zend_string_init(*ini, strlen( *ini ), 1); zend_alter_ini_entry_chars(psKey, (char *)*(ini+1), strlen( *(ini+1) ), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); zend_string_release(psKey); #else zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1, (char *)*(ini+1), strlen( *(ini+1) ), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); #endif } while (( p < argend )&&(**p == '-' )) { c = *((*p)+1); ++p; switch( c ) { case 'q': break; case 'i': if (php_request_startup() != FAILURE) { php_print_info(0xFFFFFFFF); #ifdef PHP_OUTPUT_NEWAPI php_output_end_all(); #else php_end_ob_buffers(1); #endif php_request_shutdown( NULL ); ret = 0; } break; case 'v': if (php_request_startup() != FAILURE) { #if ZEND_DEBUG php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2017 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #else php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2017 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #endif #ifdef PHP_OUTPUT_NEWAPI php_output_end_all(); #else php_end_ob_buffers(1); #endif php_request_shutdown( NULL ); ret = 0; } break; case 'c': ++p; /* fall through */ case 's': break; case 'l': source_highlight = 2; break; case 'h': case '?': default: cli_usage(); ret = 0; break; } } if ( ret == -1 ) { if ( *p ) { zend_file_handle file_handle; memset(&file_handle, 0, sizeof(file_handle)); file_handle.type = ZEND_HANDLE_FP; file_handle.handle.fp = VCWD_FOPEN(*p, "rb"); if ( file_handle.handle.fp ) { script_filename = *p; php_self = *p; SG(request_info).path_translated = estrdup(*p); SG(request_info).argc = argc - (p - argv); SG(request_info).argv = p; if (php_request_startup() == FAILURE ) { fclose( file_handle.handle.fp ); ret = 2; } else { if (source_highlight == 1) { zend_syntax_highlighter_ini syntax_highlighter_ini; php_get_highlight_struct(&syntax_highlighter_ini); highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini); } else if (source_highlight == 2) { file_handle.filename = *p; file_handle.free_filename = 0; file_handle.opened_path = NULL; ret = php_lint_script(&file_handle); if (ret==SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { zend_printf("Errors parsing %s\n", file_handle.filename); } } else { file_handle.filename = *p; file_handle.free_filename = 0; file_handle.opened_path = NULL; php_execute_script(&file_handle); ret = EG(exit_status); } php_request_shutdown( NULL ); } } else { php_printf("Could not open input file: %s.\n", *p); } } else { cli_usage(); } } }zend_end_try(); php_module_shutdown(); #ifdef ZTS tsrm_shutdown(); #endif return ret; }
ZEND_METHOD(myclass,__construct) { php_printf("this is construct method!"); }
PHP_METHOD(Test_RegexDNA, process) { HashTable *_4; HashPosition _3; zval *path, *variants, *vIUB, *vIUBnew, *stuffToRemove, *contents = NULL, *initialLength, *regex = NULL, *codeLength, *discard, *_0 = NULL, *_1, _2, **_5, *_6 = NULL, *_7; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &path); ZEPHIR_INIT_VAR(variants); array_init_size(variants, 13); ZEPHIR_INIT_VAR(_0); ZVAL_STRING(_0, "agggtaaa|tttaccct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "[cgt]gggtaaa|tttaccc[acg]", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "a[act]ggtaaa|tttacc[agt]t", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "ag[act]gtaaa|tttac[agt]ct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "agg[act]taaa|ttta[agt]cct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "aggg[acg]aaa|ttt[cgt]ccct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "agggt[cgt]aa|tt[acg]accct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "agggta[cgt]a|t[acg]taccct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "agggtaa[cgt]|[acg]ttaccct", 1); zephir_array_fast_append(variants, _0); ZEPHIR_INIT_VAR(vIUB); array_init(vIUB); ZEPHIR_INIT_VAR(vIUBnew); array_init(vIUBnew); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/B/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(c|g|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/D/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(a|g|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/H/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(a|c|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/K/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(g|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/M/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(a|c)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/N/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(a|c|g|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/R/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(a|g)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/S/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(c|g)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/V/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(a|c|g)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/W/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(a|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "/Y/S", 1); zephir_array_append(&vIUB, _0, PH_SEPARATE); ZEPHIR_INIT_BNVAR(_0); ZVAL_STRING(_0, "(c|t)", 1); zephir_array_append(&vIUBnew, _0, PH_SEPARATE); ZEPHIR_INIT_VAR(stuffToRemove); ZVAL_STRING(stuffToRemove, "^>.*$|\n", 1); ZEPHIR_INIT_VAR(discard); ZVAL_NULL(discard); ZEPHIR_INIT_VAR(contents); zephir_file_get_contents(contents, path TSRMLS_CC); ZEPHIR_INIT_VAR(initialLength); ZVAL_LONG(initialLength, zephir_fast_strlen_ev(contents)); ZEPHIR_INIT_VAR(_1); ZEPHIR_CONCAT_SVS(_1, "/", stuffToRemove, "/mS"); ZEPHIR_SINIT_VAR(_2); ZVAL_STRING(&_2, "", 0); ZEPHIR_INIT_BNVAR(_0); zephir_call_func_p3(_0, "preg_replace", _1, &_2, contents); ZEPHIR_CPY_WRT(contents, _0); ZEPHIR_INIT_VAR(codeLength); ZVAL_LONG(codeLength, zephir_fast_strlen_ev(contents)); zephir_is_iterable(variants, &_4, &_3, 0, 0); for ( ; zend_hash_get_current_data_ex(_4, (void**) &_5, &_3) == SUCCESS ; zephir_hash_move_forward_ex(_4, &_3) ) { ZEPHIR_GET_HVALUE(regex, _5); zend_print_zval(regex, 0); php_printf(" "); ZEPHIR_INIT_NVAR(_0); ZEPHIR_INIT_LNVAR(_6); ZEPHIR_CONCAT_SVS(_6, "/", regex, "/iS"); zephir_preg_match(_0, &(_0), _6, contents, discard, 1, 0 , 0 TSRMLS_CC); zend_print_zval(_0, 0); php_printf("%c", '\n'); } ZEPHIR_INIT_VAR(_7); zephir_call_func_p3(_7, "preg_replace", vIUB, vIUBnew, contents); ZEPHIR_CPY_WRT(contents, _7); php_printf("%c", '\n'); zend_print_zval(initialLength, 0); php_printf("%c", '\n'); zend_print_zval(codeLength, 0); php_printf("%c", '\n'); php_printf("%d", zephir_fast_strlen_ev(contents)); php_printf("%c", '\n'); ZEPHIR_MM_RESTORE(); }
int php_com_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int printdef, GUID *guid, int codepage) { TYPEATTR *attr; FUNCDESC *func; int i; OLECHAR *olename; char *ansiname = NULL; size_t ansinamelen; int ret = 0; if (FAILED(ITypeInfo_GetTypeAttr(typeinfo, &attr))) { return 0; } /* verify that it is suitable */ if (id_to_name == NULL || attr->typekind == TKIND_DISPATCH) { if (guid) { memcpy(guid, &attr->guid, sizeof(GUID)); } if (printdef) { char *guidstring; ITypeInfo_GetDocumentation(typeinfo, MEMBERID_NIL, &olename, NULL, NULL, NULL); ansiname = php_com_olestring_to_string(olename, &ansinamelen, codepage); SysFreeString(olename); guidstring = php_com_string_from_clsid(&attr->guid, codepage); php_printf("class %s { /* GUID=%s */\n", ansiname, guidstring); efree(guidstring); efree(ansiname); } if (id_to_name) { zend_hash_init(id_to_name, 0, NULL, ZVAL_PTR_DTOR, 0); } /* So we've got the dispatch interface; lets list the event methods */ for (i = 0; i < attr->cFuncs; i++) { zval tmp; DISPID lastid = 0; /* for props */ int isprop; if (FAILED(ITypeInfo_GetFuncDesc(typeinfo, i, &func))) break; isprop = (func->invkind & DISPATCH_PROPERTYGET || func->invkind & DISPATCH_PROPERTYPUT); if (!isprop || lastid != func->memid) { lastid = func->memid; ITypeInfo_GetDocumentation(typeinfo, func->memid, &olename, NULL, NULL, NULL); ansiname = php_com_olestring_to_string(olename, &ansinamelen, codepage); SysFreeString(olename); if (printdef) { int j; char *funcdesc; size_t funcdesclen; unsigned int cnames = 0; BSTR *names; names = (BSTR*)safe_emalloc((func->cParams + 1), sizeof(BSTR), 0); ITypeInfo_GetNames(typeinfo, func->memid, names, func->cParams + 1, &cnames); /* first element is the function name */ SysFreeString(names[0]); php_printf("\t/* DISPID=%d */\n", func->memid); if (func->elemdescFunc.tdesc.vt != VT_VOID) { php_printf("\t/* %s [%d] */\n", vt_to_string(func->elemdescFunc.tdesc.vt), func->elemdescFunc.tdesc.vt ); } if (isprop) { ITypeInfo_GetDocumentation(typeinfo, func->memid, NULL, &olename, NULL, NULL); if (olename) { funcdesc = php_com_olestring_to_string(olename, &funcdesclen, codepage); SysFreeString(olename); php_printf("\t/* %s */\n", funcdesc); efree(funcdesc); } php_printf("\tvar $%s;\n\n", ansiname); } else { /* a function */ php_printf("\tfunction %s(\n", ansiname); for (j = 0; j < func->cParams; j++) { ELEMDESC *elem = &func->lprgelemdescParam[j]; php_printf("\t\t/* %s [%d] ", vt_to_string(elem->tdesc.vt), elem->tdesc.vt); if (elem->paramdesc.wParamFlags & PARAMFLAG_FIN) php_printf("[in]"); if (elem->paramdesc.wParamFlags & PARAMFLAG_FOUT) php_printf("[out]"); if (elem->tdesc.vt == VT_PTR) { /* what does it point to ? */ php_printf(" --> %s [%d] ", vt_to_string(elem->tdesc.lptdesc->vt), elem->tdesc.lptdesc->vt ); } /* when we handle prop put and get, this will look nicer */ if (j+1 < (int)cnames) { funcdesc = php_com_olestring_to_string(names[j+1], &funcdesclen, codepage); SysFreeString(names[j+1]); } else { funcdesc = "???"; } php_printf(" */ %s%s%c\n", elem->tdesc.vt == VT_PTR ? "&$" : "$", funcdesc, j == func->cParams - 1 ? ' ' : ',' ); if (j+1 < (int)cnames) { efree(funcdesc); } } php_printf("\t\t)\n\t{\n"); ITypeInfo_GetDocumentation(typeinfo, func->memid, NULL, &olename, NULL, NULL); if (olename) { funcdesc = php_com_olestring_to_string(olename, &funcdesclen, codepage); SysFreeString(olename); php_printf("\t\t/* %s */\n", funcdesc); efree(funcdesc); } php_printf("\t}\n"); } efree(names); } if (id_to_name) { zend_str_tolower(ansiname, ansinamelen); ZVAL_STRINGL(&tmp, ansiname, ansinamelen); zend_hash_index_update(id_to_name, func->memid, &tmp); // TODO: avoid reallocation??? efree(ansiname); } } ITypeInfo_ReleaseFuncDesc(typeinfo, func); } if (printdef) { php_printf("}\n"); } ret = 1; } else { zend_error(E_WARNING, "That's not a dispatchable interface!! type kind = %08x", attr->typekind); } ITypeInfo_ReleaseTypeAttr(typeinfo, attr); return ret; }
PHP_METHOD(Test_Echoes, testEcho2) { php_printf("%f", 1.0); }
ZEND_METHOD(afk_app, run){/*{{{*/ zval **uri; char *c=NULL, *a=NULL; zval *arr = PG(http_globals)[TRACK_VARS_GET]; //从http_globals中寻找get参数,确认Controller和action的值。 if(arr && Z_TYPE_P(arr) == IS_ARRAY){ if(zend_hash_find(HASH_OF(arr), HTTP_CONTRONLLER_PARAM, strlen(HTTP_CONTRONLLER_PARAM)+1, (void **)&uri) == SUCCESS){ c = Z_STRVAL_PP(uri); }else{ c = "index"; } if(zend_hash_find(HASH_OF(arr), HTTP_ACTION_PARAM, strlen(HTTP_ACTION_PARAM)+1, (void **)&uri) == SUCCESS){ a = Z_STRVAL_PP(uri); }else{ a = "index"; } } //寻找对应的Controller和action方法所在的文件。 char *controller_path; spprintf(&controller_path, 0, "%s/controller/%s.php", APP_DIR, c); FILE *fp; //php_printf("%s\n", controller_path); //文件存在则引入该文件。不存在则报错。 if( (fp = fopen(controller_path, "r")) != NULL){ fclose(fp); int dummy = 1; zend_file_handle file_handle; zend_op_array *op_array; file_handle.filename = controller_path; file_handle.free_filename = 0; file_handle.type = ZEND_HANDLE_FILENAME; file_handle.opened_path = NULL; file_handle.handle.fp = NULL; op_array = zend_compile_file(&file_handle, ZEND_INCLUDE TSRMLS_CC); if (op_array && file_handle.handle.stream.handle) { int dummy = 1; if (!file_handle.opened_path) { file_handle.opened_path = controller_path; } php_printf("opened_path: %s\n", file_handle.opened_path); zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy, sizeof(int), NULL); } zend_destroy_file_handle(&file_handle TSRMLS_CC); if(op_array){ php_printf("execute op_array \n"); //保存旧的环境变量 zval ** __old_return_value_pp = EG(return_value_ptr_ptr); zend_op ** __old_opline_ptr = EG(opline_ptr); zend_op_array * __old_op_array = EG(active_op_array); zend_function_state * __old_func_state = EG(function_state_ptr); //执行op_array zval *result = NULL; EG(return_value_ptr_ptr) = &result; EG(active_op_array) = op_array; zend_execute(op_array TSRMLS_CC); destroy_op_array(op_array TSRMLS_CC); efree(op_array); //恢复旧的环境变量 EG(return_value_ptr_ptr) = __old_return_value_pp; EG(opline_ptr) = __old_opline_ptr; EG(active_op_array) = __old_op_array; EG(function_state_ptr) = __old_func_state; } }else{ char *error; spprintf(&error, 0, "cann't find file %s", controller_path); zend_error(1, error); } //dispatcher 调用分发的请求。 /** *在EG(class_table)查找相应的类,然后调用它的方法。 */ zend_class_entry **class = NULL; char *class_name = emalloc(strlen(c)+strlen("Controller")+1); class_name = strcpy(class_name, c); class_name = strcat(class_name, zend_str_tolower_dup("Controller", strlen("Controller")+1)); //Notice: class name need tolower. if(zend_hash_find(EG(class_table), class_name, strlen(class_name)+1, (void *)&class) != SUCCESS){ char *error; spprintf(&error, 0, "cann't find the controller class: %s ", class_name); php_printf("%s", class_name); efree(class_name); efree(class); zend_error(1, error); } efree(class_name); zval *obj, *function_name, *retval; MAKE_STD_ZVAL(obj); MAKE_STD_ZVAL(function_name); MAKE_STD_ZVAL(retval); object_init_ex(obj, *class); //php_var_dump(&obj, 1 TSRMLS_CC); ZVAL_STRINGL(function_name, "indexaction", strlen("indexaction"), 1); call_user_function(&((*class)->function_table), &obj, function_name, retval, 0, NULL TSRMLS_CC); zval_ptr_dtor(&obj); zval_ptr_dtor(&function_name); zval_ptr_dtor(&retval); //efree(class); RETURN_BOOL(1); }/*}}}*/
void apd_summary_output_footer(void) { apd_fcall_t *fcall; apd_function_entry_t *function_entry; apd_file_entry_t *file_entry; apd_coverage_t coverage; char *ret; size_t ret_len; TSRMLS_FETCH(); memset(&coverage, 0, sizeof(apd_coverage_t)); php_printf("<table border=\"1\" width=\"100%%\">\n"); php_printf("<tr>\n"); php_printf("<th>Function</th>\n"); php_printf("<th>File</th>\n"); php_printf("<th>Line</th>\n"); php_printf("<th># of calls</th>\n"); php_printf("<th>User</th>\n"); php_printf("<th>System</th>\n"); php_printf("<th>Real</th>\n"); php_printf("</tr>\n"); find_expensive(&coverage, 20 TSRMLS_CC); fcall = coverage.head; while (fcall) { function_entry = fcall->entry; file_entry = apd_array_get(&APD_GLOBALS(summary).files, fcall->file); php_basename(file_entry->filename, strlen(file_entry->filename), NULL, 0, &ret, &ret_len TSRMLS_CC); php_printf("<tr>\n"); php_printf("<td>%s</td>\n", function_entry->name); php_printf("<td><abbr title=\"%s\">%s</abbr></td>\n", file_entry->filename, ret); php_printf("<td>%d</td>\n", fcall->line); php_printf("<td>%d</td>\n", fcall->calls); php_printf("<td>%4.2f</td>\n", (double) fcall->usertime / 1000000); php_printf("<td>%4.2f</td>\n", (double) fcall->systemtime / 1000000); php_printf("<td>%4.2f</td>\n", (double) fcall->realtime / 1000000); php_printf("</tr>\n"); fcall = fcall->next; /* efree(ret); */ } php_printf("</table>\n"); zend_llist_clean(&APD_GLOBALS(summary).call_list); }
PHPAPI void php_print_info(int flag) { char **env,*tmp1,*tmp2; char *php_uname; int expose_php = INI_INT("expose_php"); time_t the_time; struct tm *ta, tmbuf; ELS_FETCH(); SLS_FETCH(); the_time = time(NULL); ta = php_localtime_r(&the_time, &tmbuf); PUTS("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n<html>\n"); if (flag & PHP_INFO_GENERAL) { char *zend_version = get_zend_version(); php_uname = php_get_uname(); PUTS("<head>"); php_info_print_style(); PUTS("<title>phpinfo()</title></head><body>"); php_info_print_box_start(1); if (expose_php) { PUTS("<a href=\"http://www.php.net/\"><img src=\""); if (SG(request_info).request_uri) { PUTS(SG(request_info).request_uri); } if ((ta->tm_mon==3) && (ta->tm_mday==1)) { PUTS("?="PHP_EGG_LOGO_GUID"\" border=0 align=\"right\" alt=\"Thies!\"></a>"); } else { PUTS("?="PHP_LOGO_GUID"\" border=0 align=\"right\" alt=\"PHP Logo\"></a>"); } } php_printf("<H1>PHP Version %s</H1>\n", PHP_VERSION); php_info_print_box_end(); php_info_print_table_start(); php_info_print_table_row(2, "System", php_uname ); php_info_print_table_row(2, "Build Date", __DATE__ ); #ifdef CONFIGURE_COMMAND php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND ); #endif if (sapi_module.pretty_name) { php_info_print_table_row(2, "Server API", sapi_module.pretty_name ); } #ifdef VIRTUAL_DIR php_info_print_table_row(2, "Virtual Directory Support", "enabled" ); #else php_info_print_table_row(2, "Virtual Directory Support", "disabled" ); #endif php_info_print_table_row(2, "Configuration File (php.ini) Path", php_ini_opened_path?php_ini_opened_path:PHP_CONFIG_FILE_PATH); #if ZEND_DEBUG php_info_print_table_row(2, "ZEND_DEBUG", "enabled" ); #else php_info_print_table_row(2, "ZEND_DEBUG", "disabled" ); #endif #ifdef ZTS php_info_print_table_row(2, "Thread Safety", "enabled" ); #else php_info_print_table_row(2, "Thread Safety", "disabled" ); #endif #if HAVE_PHP_STREAM php_info_print_table_row(2, "Experimental PHP Streams", "enabled"); #endif php_info_print_table_end(); /* Zend Engine */ php_info_print_box_start(0); if (expose_php) { PUTS("<a href=\"http://www.zend.com/\"><img src=\""); if (SG(request_info).request_uri) { PUTS(SG(request_info).request_uri); } PUTS("?="ZEND_LOGO_GUID"\" border=\"0\" align=\"right\" alt=\"Zend logo\"></a>\n"); } php_printf("This program makes use of the Zend scripting language engine:<BR>"); zend_html_puts(zend_version, strlen(zend_version)); php_printf("</BR>\n"); php_info_print_box_end(); efree(php_uname); } if ((flag & PHP_INFO_CREDITS) && expose_php) { php_info_print_hr(); PUTS("<h1 align=\"center\"><a href=\""); if (SG(request_info).request_uri) { PUTS(SG(request_info).request_uri); } PUTS("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">"); PUTS("PHP 4.0 Credits"); PUTS("</a></h1>\n"); } zend_ini_sort_entries(ELS_C); if (flag & PHP_INFO_CONFIGURATION) { php_info_print_hr(); PUTS("<h1 align=\"center\">Configuration</h1>\n"); SECTION("PHP Core\n"); display_ini_entries(NULL); } if (flag & PHP_INFO_MODULES) { int show_info_func; show_info_func = 1; zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _display_module_info, &show_info_func); SECTION("Additional Modules"); php_info_print_table_start(); show_info_func = 0; zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _display_module_info, &show_info_func); php_info_print_table_end(); } if (flag & PHP_INFO_ENVIRONMENT) { SECTION("Environment"); php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); for (env=environ; env!=NULL && *env !=NULL; env++) { tmp1 = estrdup(*env); if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */ efree(tmp1); continue; } *tmp2 = 0; tmp2++; php_info_print_table_row(2, tmp1, tmp2); efree(tmp1); } php_info_print_table_end(); } if (flag & PHP_INFO_VARIABLES) { pval **data; SECTION("PHP Variables"); php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); if (zend_hash_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_SELF", (*data)->value.str.val); } if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_AUTH_TYPE", (*data)->value.str.val); } if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_AUTH_USER", (*data)->value.str.val); } if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_AUTH_PW", (*data)->value.str.val); } php_print_gpcse_array("HTTP_GET_VARS", sizeof("HTTP_GET_VARS")-1 ELS_CC); php_print_gpcse_array("HTTP_POST_VARS", sizeof("HTTP_POST_VARS")-1 ELS_CC); php_print_gpcse_array("HTTP_POST_FILES", sizeof("HTTP_POST_FILES")-1 ELS_CC); php_print_gpcse_array("HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS")-1 ELS_CC); php_print_gpcse_array("HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS")-1 ELS_CC); php_print_gpcse_array("HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS")-1 ELS_CC); php_info_print_table_end(); } if (flag & PHP_INFO_LICENSE) { SECTION("PHP License"); php_info_print_box_start(0); PUTS("<P>\n"); PUTS("This program is free software; you can redistribute it and/or modify "); PUTS("it under the terms of the PHP License as published by the PHP Group "); PUTS("and included in the distribution in the file: LICENSE\n"); PUTS("</P>\n"); PUTS("<P>"); PUTS("This program is distributed in the hope that it will be useful, "); PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of "); PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); PUTS("</P>\n"); PUTS("<P>"); PUTS("If you did not receive a copy of the PHP license, or have any questions about "); PUTS("PHP licensing, please contact [email protected].\n"); PUTS("</P>\n"); php_info_print_box_end(); } PUTS("</BODY></HTML>"); }