PHP underlying analysis about forced splitting

藏色散人
Release: 2023-04-08 12:56:01
forward
2744 people have browsed it

Learning requires knowing what it is and why it is. The underlying knowledge of PHP is this kind of knowledge.

Recommended: "PHP Training"

Today we will talk about the knowledge about forced splitting. Simply put, forced splitting is "before the reference variable is actively assigned a value, the If a variable is assigned a value, forced splitting will occur."

It's a bit convoluted, let's take a look at the code analysis.

Look at the following code:

PHP underlying analysis about forced splitting

If you are slightly familiar with PHP: & reference symbols, you should be able to see that the output is gzchen, 8:30 in the evening, gzchen .

So let’s take a look at the underlying running process of the above code.

As we all know, a variable is a structure, which looks like this:

PHP underlying analysis about forced splitting

Comments are written on each line. This file is in zend.h in PHP Source code Zend directory.

When the code runs to line: 3[$name = '8:30 in the evening'], the structure in the memory looks like this:

PHP underlying analysis about forced splitting

When the code runs to line: 4[name], the structure becomes like this:

PHP underlying analysis about forced splitting

##Run to line: 5[

Misplaced &<span style="max-width:90%"></span>name] and line: [$nameCopy = 'gzchen'], like this:

PHP underlying analysis about forced splitting

Here, here, this is it A forced split occurred.

When is_ref__gc[reference attribute] is from 0->1, if refcont_gc>1, then forced splitting will occur. The pseudo code is:

PHP underlying analysis about forced splitting

#This is forced splitting. Variables that have been assigned by value are referenced and assigned again. The variable assigned by value will be split into a structure, in this case $myName.

This principle is basically not used in actual development, but forced splitting is usually tested together with

Copy while writing (cow) during interviews.

For more programming related content, please pay attention to the

Programming Introduction column on the php Chinese website!

The above is the detailed content of PHP underlying analysis about forced splitting. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:segmentfault.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template