Today, I was going to go to the Jackie Chan Cinema to go to the movie center 4. I bought the ticket and didn't see it yet. it will expire tomorrow. I waited for half a day for the bus and didn't wait until. I still didn't think it was.
Today, I was going to go to the Jackie Chan Cinema to go to the movie center 4. I haven't seen the ticket until now.
It will expire tomorrow. I waited for half a day for the bus. I didn't wait.
You can't just go home.
Let's continue to study the PHP kernel class today.
In PHP, class access control has three modifiers.
Public: can be accessed at will
Private: only this class can access
Protected: only this class and its subclass can access
For example
12345 |
ClassPerson {publicfunctiongetname () {} privatefunctiongetage () {} protectedfunctiongetsex (){}} |
The preceding three methods are defined, with different access levels;
How is the PHP kernel implemented?
After analysis, find the following code for Lex & Yacc:
123456 |
Class_statement: variable_modifiers {CG (access_type) = Z_LVAL ($1. u. constant);} class_variable_declaration ';' | class_constant_declaration ';' | method_modifiers function is_reference T_STRING {zend_do_begin_function_declaration (& $2, & $4, 1, $3. op_type, & $1 TSRMLS_CC);} '('parameter_list') 'method _ body {zend_do_abstract_method (& $4, & $1, & $9 TSRMLS_CC ); zend_do_end_function_declaration (& $2 TSRMLS_CC );}; |
The three access control rules are controlled in the node method_modifiers.
12345678 |
Member_modifier: T_PUBLIC {Z_LVAL ($. u. constant) = ZEND_ACC_PUBLIC;} | T_PROTECTED {Z_LVAL ($. u. constant) = ZEND_ACC_PROTECTED;} | T_PRIVATE {Z_LVAL ($. u. constant) = ZEND_ACC_PRIVATE;} | T_STATIC {Z_LVAL ($. u. constant) = ZEND_ACC_STATIC;} | T_ABSTRACT {Z_LVAL ($. u. constant) = ZEND_ACC_ABSTRACT;} | T_FINAL {Z_LVAL ($. u. constant) = ZEND_ACC_FINAL ;}; |
Here, set the value of $. u. constant according to the user input, and $ is the return value.
ZEND_ACC_PUBLIC, ZEND_ACC_PROTECTED, and ZEND_ACC_PRIVATE are defined in
Zend/zend_compile.h
123 |
# Define ZEND_ACC_PUBLIC 0x100 # define ZEND_ACC_PROTECTED 0x200 # define ZEND_ACC_PRIVATE 0x400 # define ZEND_ACC_PRIVATE 0x400 |
The general process is as follows:
Member_modifier sets the constant value of $ based on the keyword entered by the user, and returns it to method_modifiers.
Focus here
Method_modifiers function is_reference T_STRING {zend_do_begin_function_declaration (& $2, & $4, 1, $3. op_type, & $1 TSRMLS_CC );}'('
Method_modifiers: the access level set by us, public, private or protected,
Last zend_do_begin_function_declaration (& $2, & $4, 1, $3. op_type, & $1 TSRMLS_CC );
Execute this function. the last parameter is the value returned by method_modifiers.
This function is the third time we mentioned ..
Let's take a look at its definition.
Zend/zend_compile.c
123456789 |
Trim (znode * function_token, znode * function_name, intis_method, intreturn_reference, znode * fn_flags_znode TSRMLS_DC)/* {*/{omitted... zend_uint fn_flags; omitted... fn_flags = Z_LVAL (fn_flags_znode-> u. constant); omitted... op_array.fn_flags | = fn_flags ;} |
Fn_flags is a temporary variable that temporarily stores the access level returned by method_modifiers here
Finally, run op_array.fn_flags | = fn_flags. this code stores the access level in op.
When execute executes this op, it will first check whether this attribute has access permission...
1234567 |
If (fbc-> op_array.fn_flags & ZEND_ACC_PUBLIC) {// accessible} elseif (fbc-> Signature & ZEND_ACC_PRIVATE) {// private method, error} elseif (fbc-> common. fn_flags & ZEND_ACC_PROTECTED) {// protection method, error} |
The rest is what we are familiar with PHP ..