baiyanphp
所有視頻:https://segmentfault.com/a/11...前端
<?php $a = 1; while($a){ }
<?php $a = 1; do{ $a = 0; }while($a);
咱們在面試中常常會被問到以下知識點:nginx
- include和require有什麼區別? - include和include_once有什麼區別(require和require_once)同理)
<?php $a = 1;
<?php include "1.php"; $b = 2;
- ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HANDLER:表示include "1.php";語句
- ZEND_ASSIGN_SPEC_CV_CONST_RETVAL_UNUSED_HANDLER:表示$b = 2;
- ZEND_RETURN_SPEC_CONST_HANDLER:表示PHP虛擬機自動給腳本加的返回值
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE zend_op_array *new_op_array; zval *inc_filename; SAVE_OPLINE(); inc_filename = EX_CONSTANT(opline->op1); //這裏的op1就是字符串1.php new_op_array = zend_include_or_eval(inc_filename, opline->extended_value); ...
static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval *inc_filename, int type) /* {{{ */ { zend_op_array *new_op_array = NULL; zval tmp_inc_filename; ... } else { switch (type) { { case ZEND_INCLUDE_ONCE: case ZEND_REQUIRE_ONCE: { //此處帶有緩存 zend_file_handle file_handle; zend_string *resolved_path; resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), (int)Z_STRLEN_P(inc_filename)); if (resolved_path) { if (zend_hash_exists(&EG(included_files), resolved_path)) { goto already_compiled; } } else { resolved_path = zend_string_copy(Z_STR_P(inc_filename)); } if (SUCCESS == zend_stream_open(ZSTR_VAL(resolved_path), &file_handle)) { if (!file_handle.opened_path) { file_handle.opened_path = zend_string_copy(resolved_path); } if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) { //加入緩存的哈希表中 zend_op_array *op_array = zend_compile_file(&file_handle, (type==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE)); zend_destroy_file_handle(&file_handle); zend_string_release(resolved_path); if (Z_TYPE(tmp_inc_filename) != IS_UNDEF) { zend_string_release(Z_STR(tmp_inc_filename)); } return op_array; } else { zend_file_handle_dtor(&file_handle); already_compiled: new_op_array = ZEND_FAKE_OP_ARRAY; } } else { if (type == ZEND_INCLUDE_ONCE) { zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, Z_STRVAL_P(inc_filename)); } else { zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, Z_STRVAL_P(inc_filename)); } } zend_string_release(resolved_path); } break; case ZEND_INCLUDE: case ZEND_REQUIRE: new_op_array = compile_filename(type, inc_filename); //關鍵調用 break; ... return new_op_array; }
zend_op_array *compile_filename(int type, zval *filename) { zend_file_handle file_handle; zval tmp; zend_op_array *retval; zend_string *opened_path = NULL; ... retval = zend_compile_file(&file_handle, type); //核心調用 return retval; }
ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type) { ... zend_op_array *op_array = NULL; if (open_file_for_scanning(file_handle)==FAILURE) { ... } else { op_array = zend_compile(ZEND_USER_FUNCTION); //核心調用 } return op_array; }
- php_module_startup:模塊初始化
- php_request_startup:請求初始化
- php_execute_script:執行腳本
- php_request_shutdown:請求關閉
- php_module_shutdown:模塊關閉