Get the App
SLTechnology News&Howtos  ›  Development  › 

What is OPCODE in the PHP kernel

Shulou Source: shulou.com Published: 2022-06-02 19:35:10 09月23日 Update

This article is about what OPCODE is in the PHP kernel. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

OPCODE

What is OPCODE? It is an instruction that a virtual machine can recognize and process. The Zend virtual machine contains a series of OPCODE, and many things can be done through the OPCODE virtual machine. Here are a few examples of OPCODE:

ZEND_ADD adds two operands.

ZEND_NEW creates a PHP object.

ZEND_ECHO outputs the content to standard output.

ZEND_EXIT exits PHP.

For operations like this, PHP defines 186 (more kinds of OPCODE will certainly be supported as PHP is updated), and all OPCODE definitions and implementations can be found in the source zend/zend_vm_def.h file (the content of this file is not native C code, but a template, which will explain why).

Let's take a look at how PHP designs OPCODE data structures:

Struct _ zend_op {const void * handler;znode_op op1;znode_op op2;znode_op result;uint32_t extended_value;uint32_t lineno;zend_uchar opcode;zend_uchar op1_type;zend_uchar op2_type;zend_uchar result_type;}

Take a closer look at the data structure of OPCODE to see if you can find the feel of assembly language. Each OPCODE contains two operands, and the op1 and op2,handler pointers point to the function that performs the OPCODE operation. The result of the function is stored in the result.

Let's give a simple example:

Tags: Functions instructions code data processing types compilation arrays loops up and down context files logic generation content variables operands results languages procedures Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn Docker MySQL Shulou Technology