原始碼研究 php變數

2022-01-30 22:49:17 字數 1688 閱讀 1088

1、標量型別:布林型 bool,整型 int,浮點型 float,字串型 string

2、複雜型別:陣列 array,物件 object

3、特殊型別:null,資源 resource

這些變數都是怎麼實現的呢?我們都知道php是用 c 語言實現的,那是怎麼用c語言實現的呢?

來看看php5.5.7的原始碼,看是怎麼實現的,最主要的是 zval 這個結構體

在 zend/zend_types.h

typedef struct _zval_struct zval

_zval_struct 這個結構體,是在 zend/zend.h 中定義的

struct

_zval_struct ;

_zval_struct 結構體裡面有個 zvalue_value value 這個就是變數儲存的值,

zend_uchar type 這個就是變數的型別,判斷乙個變數是什麼型別,就是通過這個type來判斷的

zvalue_value

又是什麼型別的呢?它是乙個聯合體,定義如下:

typedef union _zvalue_value  str;

hashtable *ht; /*

hash table value

*/zend_object_value obj;

} zvalue_value;

看見沒, 用乙個聯合體就把php中的資料型別都定義出來了

zend_uchar type

變數型別定義, 在zend.h 中,定義了下面幾種型別:

#define is_null 0

#define is_long 1

#define is_double 2

#define is_bool 3

#define is_array 4

#define is_object 5

#define is_string 6

#define is_resource 7

#define is_constant 8

#define is_constant_array 9

#define is_callable 10

zend_uint refcount__gc

這個跟變數的垃圾**有關, php5.2 等以及以前用引用計數來進行垃圾**,php5.3 以後引入了新的垃圾**演算法concurrent cycle collection in reference counted systems,這個解決了迴圈引用的問題

其他的zend_uchar,zend_uint等都是封裝 c 語言裡面的型別

zend/zend_types.h 中定義

typedef unsigned char

zend_bool;

typedef unsigned

char

zend_uchar;

typedef unsigned

intzend_uint;

typedef unsigned

long

zend_ulong;

typedef unsigned

short zend_ushort;

cita 原始碼研究

適用環境 vim youcompleteme使用 github 源,不能使用 ustc 源 git clone depth 1 recusive所有 cargo.toml 中的庫版本號全部改為精確的細版本號,不能是粗略的大版本號 所有 cargo.toml 中的非官方託管庫,均改為 形式 第 2 3...

jQuery原始碼研究 怎麼看原始碼

這幾天有想看原始碼的想法,於是就開始了原始碼的研究,經過幾天的摸索發現看原始碼還是有點技巧在裡面的,想著把這些東東寫下來作為乙個小總結。在乙個多月前我對vue原始碼進行了一次研究,那時看原始碼的方式基本上是從上往下看,結果看著看著就看不下去了,後來找了乙個很老的版本看,但看的還是不太懂,於是想著乾脆...

struts原始碼初步研究

struts1.3.8原始碼初步學習 先介紹一下httpservlet 一下的 是有jd 反編譯工具,個人覺得還是不錯的 反編譯過來的 僅供參考 dopost方法 dohead方法 這裡負責呼叫doget或者dopost方法 多有的方法doget,dopost方法都走這裡,並交給processor去...