PHP library implementation

Source: Internet
Author: User

PHP classes and functions, so that variables are implemented in C in essence. The scripts you write will eventually be converted to C code for execution. Some may say: Isn't it converted into opcode? The problem is: opcode is only an intermediate code, and it will eventually be converted to C code for execution. Therefore, the underlying implementation of PHP is the C code.

It is precisely because PHP implementation is implemented in C language, so after downloading to the PHP source code: we also need to compile the./configure, make, and make install statements. This is because C is a compilation language. For example, a program can be made of the GUI type and the console type. For a console program, if it is written in C/C ++, it needs to be compiled first for final release. After the executable program is compiled and generated: we only need to pass the parameters required for each execution to it! You can also have a simple understanding of PHP itself: Get the PHP source code: We need to compile, generate a console-like program, and then write the PHP script: After the compilation process of lex and YACC: it is converted to various opcode commands, and these commands are finally converted to various parameters and passed into this console program for processing! If you understand this, you can understand everything:

For example, why do I need to re-compile the source code to implement a PHP module using C extension? Because this module is written in C and cannot be executed after compilation, you need to put it into the PHP source code after writing, and then compile the PHP source code that contains this part of the function, generate executable console-like programs. In this way, he can use the functions in this module.

In fact, PHP extension is not as simple as above, but the general principle is similar. The key is to remember that all PHP underlying implementations are essentially C language !! Since it is C, you must compile it before running it.

 

(I guess this section is below, and there is no basis)

According to my understanding, PHP generated various opcode commands after the compilation phase, a total of 150 types. Then you need to execute the command distribution process to each command processor. Then we can logically think of these command processors as various console executable programs. So every time you execute a PHP script: first use the C function to compile the PHP statement, generate op_array, and then send the points to each command processor for processing!

 

Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------

 

Now the problem is:

1: How does PHP convert to various Opcodes?

2: How to Write PHP extensions in C at the underlying layer? What is the principle?

The key in question 1 is that top-level PHP is a weak language, but its underlying implementation is C language, which is a strong type. How does a weak type convert to a strong type? These next blog posts will be explained again.

 

 

(Supplement: The search order for include/require another file B in file:

1: For C/C ++: search in the directory where File A is located, and then search in include_path.

2: For PHP: the opposite is true: Search in include_path and then in include_path.

 

Remember that the two search methods are different. Otherwise, it is easy to confuse which file is included when two files with the same name are written in different directories ···!)

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.