2.5 变量的检索
首先我们定义了一个指向指针的指针,然后通过zend_hash_find去EG(active_symbol_table)作用域下寻找名称为foo($foo)的变量,如果成功找到,此函数将返回SUCCESS。看完代码,你肯定有很多疑问。为什么还要进行运算,fooval明明是zval**
型的,为什么转成void**
的?而且为什么还要进行&fooval运算,fooval本身不就已经是指向指针的指针了吗?:-),该回答的问题确实很多,不要过于担心,让我们带着这些问题继续往下走。
所以当我们去HashTable里寻找变量的时候,得到的值其实是一个zval的指针。In order to populate that pointer into a calling function’s local storage,the calling function will naturally dereference the local pointer,resulting in a variable of indeterminate type with two levels of indirection (such as void**
).Knowing that your “indeterminate type” in this case is zval*
,you can see where the type being passed into zend_hash_find() will look different to the compiler,having three levels of indirection rather than two.This is done on purpose here so a simple typecast is added to the function call to silence compiler warnings.
就去符号表里找变量而言,SUCCESS和FAILURE仅代表这个变量是否存在而已。