Table of Contents
How PHP variables are stored in zend kernel
Home Backend Development PHP Tutorial How PHP variables are stored in zend kernel_PHP tutorial

How PHP variables are stored in zend kernel_PHP tutorial

Jul 13, 2016 am 09:45 AM
Kernel variable Way

How PHP variables are stored in zend kernel

Variables in PHP can save any data type because it is a weakly typed language. But PHP is written in C language. C language is a strongly typed language. Each variable has a fixed type. You cannot change the type of the variable at will (you can force type conversion, but problems may occur). In the zend engine, it is How can a variable save any type?
In the zend/zend.h header file, you will find the following structure:

<code>typedef struct _zval_struct zval;

typedef union _zvalue_value {
    long lval;
    double dval;
    struct {
        char *val;
        int len;
    }str;
    HashTable *ht;
    zend_object_value obj;
} zvalue_value ;

struct _zval_struct {
    zvalue_value value;
    zend_uint refcount;
    zend_uchar type;
    zend_uchar is_ref;
};
</code>
Copy after login

The zval structure is the expression of commonly used PHP variables in the kernel. In the zval structure, you can see 4 member variables, namely:

<code>zvalue_value value;  //变量的值,PHP变量的值就保存在这里
zend_uint refcount;  //变量引用数,变量引用计算器
zend_uchar type;     //变量的类型
zend_uchar is_ref;   //变量是否被引用
</code>
Copy after login

The value member variable of the zval structure is a zvalue_value union. PHP can maintain any structure type because of this union . As can be seen from the member variables of the zvalue_value union, different types will be saved in different member variables, so that PHP variables can store any data type. For example, when the variable is an integer type, it will be saved to the lval member variable of value; when the variable type is a string, it will be saved to the str member variable of value.

How PHP variables are stored in zend kernel_PHP tutorial
Another question is, how does the zend engine know what type this variable saves? We noticed that there is a type member variable in the zval structure. This member variable is to save the type of a php variable.
The zend engine defines 8 variable types:

<code>#define IS_NULL 0
#define IS_LONG 1
#define IS_DOUBLE 2
#define IS_STRING 3
#define IS_ARRAY 4
#define IS_OBJECT 5
#define IS_BOOL 6
#define IS_RESOURCE 7
</code>
Copy after login

Each macro definition corresponds to a type of the PHP language layer. For example, when the type member variable of zval is equal to IS_STRING (zval.type==IS_STRING), it means that the type of this variable is a string type.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1043340.htmlTechArticleHow PHP variables are stored in zend kernel Variables in PHP can save any data type, this is because it It is a weakly typed language. But php is written in C language, which is a strongly typed language...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

A guide to using Windows 11 and 10 environment variables for profiling A guide to using Windows 11 and 10 environment variables for profiling Nov 01, 2023 pm 08:13 PM

Environment variables are the path to the location (or environment) where applications and programs run. They can be created, edited, managed or deleted by the user and come in handy when managing the behavior of certain processes. Here's how to create a configuration file to manage multiple variables simultaneously without having to edit them individually on Windows. How to use profiles in environment variables Windows 11 and 10 On Windows, there are two sets of environment variables – user variables (apply to the current user) and system variables (apply globally). However, using a tool like PowerToys, you can create a separate configuration file to add new and existing variables and manage them all at once. Here’s how: Step 1: Install PowerToysPowerTo

How to install the Linux kernel on Ubuntu 22.04 Detailed tutorial! How to install the Linux kernel on Ubuntu 22.04 Detailed tutorial! Mar 01, 2024 pm 10:34 PM

To install the Linux kernel on Ubuntu22.04, you can follow the following steps: Update the system: First, make sure your Ubuntu system is the latest, execute the following command to update the system package: sudoaptupdatesudoaptupgrade Download the kernel file: Visit the official Linux kernel website () to download Required kernel version. Select a stable version and download the source code file (with .tar.gz or .tar.xz extension), for example: wget Unzip the file: Use the following command to unzip the downloaded kernel source code file: tar-xflinux-5.14.tar. xz install build dependencies: Install the tools and dependencies required to build the kernel. Execute

Strict mode for variables in PHP7: how to reduce potential bugs? Strict mode for variables in PHP7: how to reduce potential bugs? Oct 19, 2023 am 10:01 AM

Strict mode was introduced in PHP7, which can help developers reduce potential errors. This article will explain what strict mode is and how to use strict mode in PHP7 to reduce errors. At the same time, the application of strict mode will be demonstrated through code examples. 1. What is strict mode? Strict mode is a feature in PHP7 that can help developers write more standardized code and reduce some common errors. In strict mode, there will be strict restrictions and detection on variable declaration, type checking, function calling, etc. Pass

Modify Linux kernel startup sequence Modify Linux kernel startup sequence Feb 23, 2024 pm 10:22 PM

Modify the kernel startup sequence of Linux 1. Modify the kernel startup sequence of RHEL6/CentOS6. Check the /etc/grub.conf file to determine the system kernel situation. According to the document, there are two kernel versions in the system, namely 2.6.32-573.18.1.el6.x86_64 and 2.6.32-431.23.3.el6.x86_64. Kernel versions are listed from top to bottom. In the grub.conf file, you can decide which kernel version to use when the system starts by adjusting the default parameters. The default value is 0, which means the system will boot the latest kernel version. A value of 0 corresponds to the first content listed in the grub.conf file.

Mind map of Python syntax: in-depth understanding of code structure Mind map of Python syntax: in-depth understanding of code structure Feb 21, 2024 am 09:00 AM

Python is widely used in a wide range of fields with its simple and easy-to-read syntax. It is crucial to master the basic structure of Python syntax, both to improve programming efficiency and to gain a deep understanding of how the code works. To this end, this article provides a comprehensive mind map detailing various aspects of Python syntax. Variables and Data Types Variables are containers used to store data in Python. The mind map shows common Python data types, including integers, floating point numbers, strings, Boolean values, and lists. Each data type has its own characteristics and operation methods. Operators Operators are used to perform various operations on data types. The mind map covers the different operator types in Python, such as arithmetic operators, ratio

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

What are instance variables in Java What are instance variables in Java Feb 19, 2024 pm 07:55 PM

Instance variables in Java refer to variables defined in the class, not in the method or constructor. Instance variables are also called member variables. Each instance of a class has its own copy of the instance variable. Instance variables are initialized during object creation, and their state is saved and maintained throughout the object's lifetime. Instance variable definitions are usually placed at the top of the class and can be declared with any access modifier, which can be public, private, protected, or the default access modifier. It depends on what we want this to be

PHP function introduction—is_string(): Check whether the variable is a string PHP function introduction—is_string(): Check whether the variable is a string Jul 24, 2023 pm 09:33 PM

PHP function introduction—strpos(): Check whether a variable is a string In PHP, is_string() is a very useful function, which is used to check whether a variable is a string. When we need to determine whether a variable is a string, the is_string() function can help us achieve this goal easily. Below we will learn about how to use the is_string() function and provide some related code examples. The syntax of the is_string() function is very simple. it only needs to

See all articles