深入理解PHP传参原理(PHP5.2)
首先说下今天想到的一个问题。在编写php扩展的时候,似乎参数(即传给zend_parse_parameters的变量)是不需要free的。举例:
PHP_FUNCTION(test)
{
char* str;
int str_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
RETURN_FALSE;
} php_printf(str); // 无需free(str)
}
运行正常:
test("Hello World"); // 打印Hello World
这里不用担心test函数会发生内存泄露,php会自动帮我们回收这些用于保存参数的变量。
那php究竟是如何做到的呢?要解释这个问题,还是得看php是怎么传递参数的。
EG(argument_stack)简介
简单来讲,在php中的EG中保存了一个专门用于存放参数的栈,名为argument_stack。每当发生函数调用的时候,php会将传入的参数压进EG(argument_stack)。一旦函数调用结束,则EG(argument_stack)被清理,并且等待下一次的函数调用。
关于EG(argument_stack)的struct结构、用途,php5.2和5.3实现有一些区别。本文主要以5.2为例,5.3+的变化后面抽空再说。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJsAAADACAIAAACcSobvAAAGaElEQVR4nO2dsa76NhhH/4/Vt0B9gG4dWfoIqBsPgNTOlVDF3g2JSgzsiPUObGFmd4eExA5OYpNcx/n1WGfgGuMbfGLn4nz344ehaJUfcx8AZeKCUbWCUbWCUbWCUbXSGN39/e9Pv2xhKfz+5z8DRmc/RIglyOhqc4T8wagaGFUDo2pgVA2MqoFRNaYxur0ZY8z5UNdc9g9zP13eHjfPvhr7n3VrILXRy/5h7o+nMcUWo3MzndHTtcMiRpdq9LI6FMY89zuMyhgtL6i3K0Z1jK52X3fz3O8wKmO0nKaP4tyquV2t9tezwehyjJbCjLFqDoWxPtusT0/z+Fp3+sNodkaP69PTMfqSWpVGZ/Vaq1Qrtlsz/zAtCPaM1MCoGhhVA6NqYFSNCKOwIDCqBquuDhhVIy+jxphvem1gz61mIa/6vp4/I2uj72/be6B2GezW26auLB+0fhxjdEzPizQ6aGj8O/eeFl3NWr9xUEDLU3+bqJ6XZHR9enbdWpn27QWeKD0N+s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VZdHTCqBkbVwKgaGFUDo2pgVI25jVrBD2z2TsK8RlshZ9winYCJjI6P7iQqJSej46M7+TrgvIx6xQR/j/fmuOLLY7MzOi66sxWzAnMbHRfd2aSWg1yMjvgeb/6BKUujH0d3OhPXqofZjQ5CdGcyEhklujMZyfaMiO5MxNz7ujA1GFUjwigsCIyqwaqrA0bVwKgaGFUDo2pgVI3ZjV7PxhAzNiFzGq3udRNhNCkTGR0TC4jR/IyOiwXEaH5GLT6IBcRojkbHxAJiNDujIzM9YjQ7oyNiATGapdGPYwFbf/3iNR+jgxALmIxERokFTEayPSNiARMx+74uTAxG1YgwCgsCo2qw6uqAUTUwqgZG1cCoGhhVA6NqTGO0vFNm3Tuz9+Lf9+XtG23+Z9n4ndfoZf8w94edlgijAkZP1w6LGF2q0YuVURWjGkabO9sYVTH6CgPDqIzRKtVfcW7VOIGAdnJkjGZv9PXvZlbNoTDWZxs3igyjCzBaRu26VuxATiedoxN/ZF4rtlsz/zAtCPaM1MCoGhhVA6NqYFSNCKOwIAaM/rr5a/ZDhHB+/u2PAaMUjYJRtYJRtfIf7Gtrvv0JvJgAAAAASUVORK5CYII=" alt="" />
上图是5.2中argument_stack的大概示意图,看起来简单明了。其中,栈顶和栈底固定为NULL。函数接收的参数按照从左到右的顺序,依次被压入栈。注意,最后会被额外压入一个long型的值,表示栈里的参数个数(上图中为10)。
那被压入argument_stack的参数究竟是什么呢?其实是一个个zval类型的指针。它们指向的zva有可能是CV变量,有可能是is_ref=1的变量,还有可能是一个常量数字,或者常量字符串。
EG(argument_stack)在php5.2中被具体实现为zend_ptr_stack类型:
typedef struct _zend_ptr_stack {
int top; // 栈中当前元素的个数
int max; // 栈中最多存放元素的个数
void **elements; // 栈底
void **top_element; // 栈顶
} zend_ptr_stack;
初始化argument_stack
初始化argument_stack的工作是发生在php处理具体的请求之前,更准确说是处于php的php_request_startup->zend_activate->init_executor过程之中。
在init_executor函数里我们发现如下2行:
zend_ptr_stack_init(&EG(argument_stack));
zend_ptr_stack_push(&EG(argument_stack), (void *) NULL);
这2行分别代表着,初始化EG(argument_stack),紧接着压入一个NULL。由于EG是个全局变量,因此在实际调用zend_ptr_stack_init之前,EG(argument_stack)中的所有数据全部为0。
zend_ptr_stack_init实现很简单。
ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
{
stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE);
stack->max = PTR_STACK_BLOCK_SIZE; // 栈的大小被初始化成64
stack->top = ; // 当前元素个数为0
}
一旦argument_stack被初始化完,则立即会被压入NULL。这里无须深究,这个NULL其实没有任何的含义。
NULL入栈之后,整个argument_stack的实际内存分布如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUcAAAB/CAIAAADzdZdIAAAMfUlEQVR4nO2dz2vbTBrH8//kH3jp7nt6lz300r4Hn7wvrPeHT768WVhyaUnaJRAteEu2a3a9Bx8aMK998Avl3RyMEzsYY4Ix1I4T0pCYxITESXFKKxKMCdrD2NLoh2XZkjwzyvfDc2gVSZFm9MmMRppHCwoAIFgssD4AAIDHwGoAggasBiBowGoAggasBiBowGoAggasBiBo8GZ1JrSwEMqwPorZ2V9ZXFhc2Wd9GOBRA6u9BVYD9gTHag99crErWA3YA6u93RWsBuxxZ/X+yuKCxuhqppeqhu6vLC6EMtqPKHUzIW3tiVYb97O4sm91HGS14Z7t/0zoD9fylLQj1CtLLR/+DtrqTGji7wbABzxqqzOh0fW+v7KoXcrUNU5soS94shK9/tCoiVbrJaJ2pCmn/3UT9mdczbQr9T/aeRrONBPSTn9xZV+/JgBzxROrqSvYKEkmtGC43PXLLdafbLXlBmarHUm1v7Jo0s9mY/V8xqxElq4IPuYHxMYDq3Wtkr4DS/VZzVYvhDKjDrV+Z3O1mj5miy6G+jsse+XmI7W8xQBgrri22tDTHGuTjdVu2mqtGzy71aZNdBvrOtoO2+p9dMABQ1xabb549RLol1tYPeN9NX1/Tt+46wbnXFlt2XDruuv299VjCwIAv3F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ylU1r9JPKG/mzdcqoW3aiEpdLb94fuP1ILwDg8tdqQaWz4dbWCseesLR8TDFKXOstbOqXV30b/TX+2rtHu4c4ZzAFPrdYlJypQCcMM98OTEokxSF06ZYZDZ1a7fw8cgBkQoK2mwr/UpbAaBAcvrNYnA9R/BtXivppaPi7mn7p02rylsBrwi2c5RunxpyH6T5yWi8Oc+86+ejXn1KXO8pbCaiAC83m3TKR3wrwKWA1YAathNQgaDK3WdYNVmGTkh9UgSIg1u0OkgNWAFbAaVoOggWyE/sbcKhIAFTur8YVElzHuk4UA+Iqd1QAAEYHVAAQNWA1A0IDVAAQNWA1A0IDVAAQNWA1A0Pg/9/xr++1XGL4AAAAASUVORK5CYII=" alt="" />
参数入栈
在压入第一个NULL之后,一旦再有参数入栈,则argument_stack会发生如下动作:
stack->top++;
*(stack->top_element++) = 参数;
我们用一段简单的php代码来说明问题:
function foo( $str ){
print_r();
}
foo("hello world");
上述代码在调用foo的时候,传入了一个字符串常量。因此,实际上被压入栈的是一个指向存储“hello world”的zval。用vld来查看编译之后的opcode:
line # * op fetch ext return operands
---------------------------------------------------------------------------------
3 0 > NOP
6 1 SEND_VAL OP1[ IS_CONST (458754) 'hello world' ]
2 DO_FCALL 1 OP1[ IS_CONST (458752) 'foo' ]
15 3 > RETURN OP1[ IS_CONST (0) 1 ]
SEND_VAL指令实际上做的事情就是将“hello world”压入argument_stack。
int ZEND_SEND_VAL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
……
zval *valptr, *value; value = &opline->op1.u.constant;
ALLOC_ZVAL(valptr);
INIT_PZVAL_COPY(valptr, value);
if (!) {
zval_copy_ctor(valptr);
} // 入栈,valptr指向存放hello world的zval
zend_ptr_stack_push(&EG(argument_stack), valptr);
……
}
入栈完成之后的argument_stack为:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAd4AAACKCAIAAACLlLzBAAAXVElEQVR4nO2da2/bVoKG/X/8B7TJNGgw222aXpJ+EIqFoU6d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jgdC3GjsluzMQ80AAE0Ofj58MXwpEOKePXvFc4u1X54795dAiDt2JrLzSD4zANQMAGjG8vebpFnj+NtfoO5su5cDIe5vs0XlaYeaAQAtyBSWiZ2P9X2GdmfrefnCd8+evUK8LHv6JwI1AwBaU7y3/txbnxCbHH/7i+ffSb7y/i3PHcdcTpz/+ng4Rp77HTsT+Wbyn1onHGoGAOhi78efol9lSPVZzNEzY8f6PkNa5siv/kift8FL1+9vP2pytqFmAIAB7m8/+vP1/NmRa56PkM5i3hyeiH6VkfWTUwVqBgAA3wE1AwCA74CaAQDAd/w/EN0breG6JogAAAAASUVORK5CYII=" alt="" />
参数个数
前文说到,实际上并非把所有参数入栈就完事了。php还会额外压入一个数字,表示参数的个数,这个工作并非发生在SEND_XXX指令的时候。实际上,在真正执行函数之前,php会将参数个数入栈。
继续沿用上面的例子,DO_FCALL 指令用于调用foo函数。在调用foo之前,php会自动填入argument_stack最后一块。
static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
{
……
// 在argument_stack中压入2个值
// 一个是参数个数(即opline->extended_value)
// 一个是标识栈顶的NULL
zend_ptr_stack_2_push(&EG(argument_stack), (void *)(zend_uintptr_t)opline->extended_value, NULL);
……
if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
……
}
else if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
……
// 调用foo函数
zend_execute(EG(active_op_array) TSRMLS_CC);
}
else { /* ZEND_OVERLOADED_FUNCTION */
……
}
……
// 清理argument_stack
zend_ptr_stack_clear_multiple(TSRMLS_C);
……
ZEND_VM_NEXT_OPCODE();
}
压入参数个数和NULL之后,用于foo调用的整个argument_stack已然完成。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeUAAACpCAIAAACav7KWAAAayElEQVR4nO2d/U8bZ4LH+X/4B3zJNmq012ubviT9wepJyN2S69JVa91tslWKVgsliYSW2Vu35RL36rZHV0Hr1lZrrdiUKBZgkOW1WB+rYBwEkaH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ynWpdWteGr7xT6/9ZyDEffvd98pTAF8DAPTyp6l8o4qNXiL25OlfxQIhbmzipur3D18DAPRy+NPRC+GrgRD39Fufuq627ssz5/4cCHEnzkb2HqgvvwBfAwAMsP5tlbSKnHz7M9SyLZd1IMT9daGo9eXD1wAAY8wX1omyTwx8hLbszvPS8I2n3/qUyFr1MaMAfA0AMEzxzt1n3vyQKObk2589+07y5fduui4+5vLcha9OhifIA8YTZyNfz/yj9dcOXwMAzHDww4/RL+dJRVvI8bPjJwY+Qtrm2C/+SH9vQ1envtt90PY7h68BAOb5bvfBn6byb41+4fqM8yzmjYuT0S/nVbvuqQJfAwAAG8DXAADABvA1AACwAXwNAABs8P+g9TFc0h8IJQAAAABJRU5ErkJggg==" alt="" />
获取参数
继续跟进上面的例子。让我们深入到foo函数,看看foo的opcode是什么样子的。
line # * op fetch ext return operands
---------------------------------------------------------------------------------
3 0 > RECV OP1[ IS_CONST (0) 1 ]
4 1 SEND_VAL OP1[ IS_CONST (5) 123 ]
2 DO_FCALL 1 OP1[ IS_CONST (459027) 'print_r' ]
5 3 > RETURN OP1[ IS_CONST (0) null ]
第一条指令是RECV,从字面上理解便是用于获取栈中参数的。实际上,SEND_VAL和RECV有点对应的感觉。每次函数调用之前SEND_VAL,在函数内部进行RECV。为什么不说是完全对应,实际上RECV指令并非一定需要。只有当用户定义的函数被调用是,才会产生RECV。我们编写的扩展函数,php自带的内建函数,都不会有RECV。
需要额外指出的是,每次SEND_VAL和RECV 均只能处理一个参数。也就是说如果传参的过程中有多个参数,那么会产生若干SEND_VAL以及若干RECV。这里引出一个很有趣的话题,传入参数和获取参数的顺序是怎样的呢?
答案是,SEND_VAL会将参数从左至右的进行压栈,而RECV一样的从左至右获取参数。
static int ZEND_RECV_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
……// param拿参数的顺序是沿着栈顶-->栈底
if (zend_ptr_stack_get_arg(arg_num, (void **) ¶m TSRMLS_CC)==FAILURE) {
……
} else {
zend_free_op free_res;
zval **var_ptr; // 验证参数
zend_verify_arg_type((zend_function *) EG(active_op_array), arg_num, *param TSRMLS_CC);
var_ptr = get_zval_ptr_ptr(&opline->result, EX(Ts), &free_res, BP_VAR_W); // 获取参数
if (PZVAL_IS_REF(*param)) {
zend_assign_to_variable_reference(var_ptr, param TSRMLS_CC);
} else {
zend_receive(var_ptr, *param TSRMLS_CC);
}
} ZEND_VM_NEXT_OPCODE();
}
zend_assign_to_variable_reference 和 zend_receive 都会完成“获取参数” 。“获取参数”不太好理解,实际它究竟是做哪些事情呢?
说到底很简单,“获取参数”就是将这个参数添加到当前函数执行期间的“符号表”中,具体对应为EG(current_execute_data)->symbol_table。本示例中,RECV完成之后,函数体内的symbol_table中有了一个符号‘str’,它的值为“hello world”。
但argument_stack并没有发生一丝变化,因为RECV仅仅是读取参数,而不会对栈产生类似pop操作。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeUAAACpCAIAAACav7KWAAAayElEQVR4nO2d/U8bZ4LH+X/4B3zJNmq012ubviT9wepJyN2S69JVa91tslWKVgsliYSW2Vu35RL36rZHV0Hr1lZrrdiUKBZgkOW1WB+rYBwEkaHgS4kNJVFwk1IUzf3w2DPPvNkz43l7PN+Pvj+QYebxy8x88vDM89LDAwAAYIEet98AAAAAXcDXAADABvA1AACwAXwNGkS/nA+EOISVXI594/YlA5wGvgYNXBcQYjRuXzLAaeBr0IAo4PTFGcT7ga/9CXwNGsDXDAW+9ifwNWgAXzMU+NqfwNegAXzNUOBrfwJfgwbwNUOBr/0JfA0awNcMBb72J/C177h3/9Hh0RPldviaocDX/gS+9h1XplaDo3Ox6bV79x/R2+FrhgJf+xP42o/cu/9oIn0nODo3dG0ps7xDNsLXDAW+9ifwtX85PHqSXrp7PrbYH8kmFjbha4YCX/sT+Brw1xcrp4bT8DVDga/9CXztXw6PniQWNgfGc/2R7JlLM/A1Q4Gv/Ql87VMyyzt93PyVqdXC+t752OLQtSX4mqHA1/4EvvYd9+4/Oh9bHJw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H34Ux7CBGltIcCQTGKQlBns75Me6YpXNlDNcXGi2q+bnZMkPy9TvClryWNEgJGmx08G/gadB/O+LphRkljJp8tVXnaD0nJP4maVZ9L8bysswOv1U5Ci1i9QH+0h/gx8DXoPhx63ijVYjhT5/l6PCnZKK2DEy+r9DqTt3FrCVe+XaNA+LpbA1+D7sOp/iG0LvPxGlEk3c1M1sat0uTdiOzpZdf7GukkVt8vALiJY/35xHqx0KOjubE5AkM+s5Df69dvXJx03XdM55VzH9twywDgGs71vxbMSBqvk9TGUlEUd3N/Y+3X7X3NYPs1AADQODheptH6kS3x0pk+eZ6vb9d4eeuHojvHadVegLp93SxQrb8gfA0A8D5Ojm8U/UiNnRH7RCtmidDoLi1t09Dva+l0yg1qddSvAQBs4Oh49GZfaUmjhFo9WvnbBrq83Go7/X+AMBMGfA0AYICGr0fSDinbxzn2+vvwNQDAPK/97vNAiHtx6BvXddb10epgBl8DAHTx6z8kAyHu+XdTruusu/PS8A2tDmbwNQBAFx9MzgZC3M//45rrRuvuPPtOMhDi3hr9QnkK4GsAgC7+dmsjEOKeeuOK60br7px8+7NAiPvka5U5luBrAIAuDn86OnE2EghxL/x2ynWpdWteGr7xT6/9ZyDEffvd98pTAF8DAPTyp6l8o4qNXiL25OlfxQIhbmzipur3D18DAPRy+NPRC+GrgRD39Fufuq627ssz5/4cCHEnzkb2HqgvvwBfAwAMsP5tlbSKnHz7M9SyLZd1IMT9daGo9eXD1wAAY8wX1omyTwx8hLbszvPS8I2n3/qUyFr1MaMAfA0AMEzxzt1n3vyQKObk2589+07y5fduui4+5vLcha9OhifIA8YTZyNfz/yj9dcOXwMAzHDww4/RL+dJRVvI8bPjJwY+Qtrm2C/+SH9vQ1envtt90PY7h68BAOb5bvfBn6byb41+4fqM8yzmjYuT0S/nVbvuqQJfAwAAG8DXAADABvA1AACwAXwNAABs8P+g9TFc0h8IJQAAAABJRU5ErkJggg==" alt="" />
清理argument_stack
foo内部的print_r也是一个函数调用,因此也会产生压栈-->清栈的操作。因此print_r执行之前的argument_stack为:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeIAAADrCAIAAAA68wKIAAAgAElEQVR4nO2d/W8T17rv+X/4B7zhFhXt01MKgbS6iiqdyG3D7QlbYO2z4VY0p6d5Kzq5YnpqaA64uymV9xbRNo0FvlVKQZgEO7K8fbO9s5UYExGUmCQKiUPqIOKGula07g/LLzPjsT0znrc18/3qq6qMZ5btmVmfLD/rmfXsIxAEQZCFtc/sDwBBEAQ1EjANQRBkaQHTECGE+L6LutwczIovjPxo9i0DGSdgGiKEENO5Ayu12bcMZJyAaYiQMqbbBydg6xuYdpqAaYgQYJopA9NOEzANEQJMM2Vg2mkCpiFCgGmmDEw7TcA0RAgwzZSBaacJmIYIAaaZMjDtNAHTECHANFMGpp0mYNpZujI+H3+Urd0OTDNkYNppAqadpfDMWo8/2TH0wBtK83kNTDNkYNppAqadqNxO4fb06rmR6QqvgWmGDEw7TcC0o7WxvTs2lTnaFwamGTIw7TQB045WZG69yxvrGHoATDNkYNppAqYdqo3tXY8v0eNPekPpLm8MmGbIwLTTBEw7UYvrLzu5aCi+7A8/8fgSG9u7wDRDBqadJmDacUoubHVy0fDMmjeU7vEn86+KBJkeTBmYdpqAaWdpY3u3k4tG5tZ7r89cDKYKxT26HZhmyMC00wRMO0iF4l73cDwUX/b4EiN3HvNfAqYZMjDtNAHTDpI3lPaG0oXi3vzqC9FLwDRDBqadJmDaKaLPs1SiHCIB0wwZmHaagGlHKLdT6OSii+sv6+0ATDNkYNppAqYdIW8oLQpGi2R6AVZYqQ27eSDTBUzbX/OrLzq5aL1wB9Xx3/tM5w4s34c/vGzY/QOZLmDa/vL4EuGZtcb7mM4dWKmNuXkgKwiYtrnij7IeX6LpbrTnmx51heUYmHaagGmby+NLSNYBEAmYZsjAtNMETNtZMofSBJhmysC00wRM21kyh9IEmGbKwLTTBEzbVvKH0gSYZsrAtNMETNtW8ofSBJhmysC00wRM21N0RenGudJ8ycE0lyaEkFiwsi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f77v7+ulrlNGimcOKgGkIgpQp9WTtjVNfUrIcPvPtmx8FT/TfM513zPnI+ZuHPX46Z3jopPfWxD/qnXBgGoIgxdr5+Rffd1E6rK744MnhQ91fwU194P0v+Oet9+r4s+cvGpxtYBqCIJV69vzFn8cTp4dumL7CO4v+cHDU911UlHsnKWAagiDI0gKmIQiCLC1gGoIgyNL6/y3qsCt6xqqjAAAAAElFTkSuQmCC" alt="" />
print_r执行之后argument_stack又回到了foo刚RECV完的状态。
具体调用print_r的过程并非本文阐述的重点。我们关心的是当调用foo结束之后,php是如何清理argument_stack的。
上面展示的do_fcall代码片段中可以看出,清理工作由zend_ptr_stack_clear_multiple完成的。
static inline void zend_ptr_stack_clear_multiple(TSRMLS_D)
{
void **p = EG(argument_stack).top_element-;
// 取栈顶保存的参数个数
int delete_count = (int)(zend_uintptr_t) *p;
EG(argument_stack).top -= (delete_count+); // 从上至下,依次清理
while (--delete_count>=) {
zval *q = *(zval **)(--p);
*p = NULL;
zval_ptr_dtor(&q);
}
EG(argument_stack).top_element = p;
}
注意这里清理栈中zval指针,使用的是zval_ptr_dtor。zval_ptr_dtor会将refcount减1,一旦refcount减为0,则保存该变量的内存区域会被真正的回收掉。
在本文示例中,foo调用完毕之后,保存“hello world”的zval状态为:
value "hello world"
refcount 1
type 6
is_ref 0
由于refcount只剩1,因此,zval_ptr_dtor会将“hello world”真正从内存中销毁。
消栈完毕之后的argument_stack内存状态为:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAewAAACGCAIAAACQUC6/AAAdNElEQVR4nO2d/VMUV7qA+X/4B3pxYXWJX8hHcreo3L3UqLCIWZ0YNV4lXoEhucte2zgqwVGIFomSxcwscg1+FQMI7NSENYSUDOhVF1AoNYOGWGGMImWd+8OZ6T79Of01fbqH96n3B2j6a+jup8+8ffq8OQgAAABwLTm0dwAAAAAwDkgcAADAxYDEAQAAXAxdiQfLc3LKg1R3wRQTvtycXN8E7d0AAGDlAhI3A0gcAADKuFXiFurTxK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MX8P2FDhF0ERaFTAAAAAElFTkSuQmCC" alt="" />
可以看出上图中的argument_stack与刚被初始化之后是一样的。此时argument_stack真正做好了迎接下一次函数调用的准备。
回到文章刚开始的问题...
为何无需free(str)呢?弄明白了argument_stack之后就很好理解这个问题了。
因为str指向的是zval中实际存放“hello world”的内存地址。假设扩展函数如下:
PHP_FUNCTION(test)
{
char* str;
int str_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
RETURN_FALSE;
} str[] = 'H';
}
则调用
$a = "hello world";
test($a);
echo $a;
会输出“Hello world”。尽管我们调用test的时候,并非是传 $a 的引用,但实际效果相当于 test(&$a) 。
简单来说,内存中只有一份 $a ,不管是CV数组中,还是在argument_stack中。而zend_parse_parameters并没有拷贝一份数据用于函数执行,事实上它也不能这么做。因此,当函数完毕之后,如果没有其他地方会用到$a,php清理argument_stack时会帮我们free。如果仍然其他代码在使用,就更加不能手动free了,否则会破坏 $a 的内存区域。
需要注意的是,并非写扩展函数中用到的每个变量,php都会自动回收。所以该free的时候,切勿手软:)
深入理解PHP传参原理(PHP5.2)的更多相关文章
- 浅谈对java中传参问题的理解
之前用的c/c++比较多,在c/c++中对于传参类型,无外乎就是传值.传引用.传指针这几种.但在java中,由于没有指针类型,其传参的方式也发生了相应的变化.在网上找了找,按我之前的理解,java中传 ...
- python3 函数传参练习 全局变量与局部变量 的理解
额 还是继续抄一边NLP第二条: 2.一个人不能控制另外一个人 一个人不能改变另外一个人,一个人只能改变自己. 每个人的信念,价值观,规条系统只对本人有效,不应强求别人接守. 改变自己,别人才会有 ...
- 以Integer类型传参值不变来理解Java值传参
最近在写代码的时候出了一个错误,由于对值引用理解的不深,将Integer传入方法中修改,以为传入后直接修改Integer中的值就不用写返回值接收了,虽然很快发现了问题,但还是来总结一下 首先是代码: ...
- C/C++函数调用时传参过程与可变参数实现原理
C/C++函数调用时传参过程与可变参数实现原理 C语言的经典swap问题 在学习C语言的时候,我们大都遇到过一些经典例题,这些经典例题背后所代表的是往往是C/C++背后的一些运行原理,比如下面这个示例 ...
- 深入理解 JavaScript中的变量、值、传参
1. demo 如果你对下面的代码没有任何疑问就能自信的回答出输出的内容,那么本篇文章就不值得你浪费时间了. var var1 = 1 var var2 = true var var3 = [1,2, ...
- HTTP协议GET方法传参最大长度理解误区
结论 HTTP 协议未规定GET和POST的长度 GET的最大长度是因为浏览器和WEB服务器显示了URI的长度 不同浏览器和WEB服务器,限制的最大长度不同 若要支持IE,则最大长度为2083 byt ...
- 【C/C++】指针,传参,引用的一些个人理解。
(以下均为个人理解) 函数访问的传参两种方式大致为: 值传递: 地址传递. 但是实际上可以都理解为,传进来的[形参]是主函数里的实参值的[一种复制]. 举个例子,哪怕我们将地址作为子函数的输入变量,形 ...
- 关于C中函数传参的一点理解
一般来说c传值分为传值与传指针,Java里没有指针,因此只有传值,但是Java里传值分为简单变量传值和引用型变量传值,从本质上来说这两者没啥区别. 下面主要说的是传参时对原变量的影响: 最初练习创建单 ...
- 关于Python中包裹传参和解包裹的理解
1.包裹传参 首先思考一个问题:为什么要有包裹传参?原因包括但不仅限于以下两点:①不确定参数的个数.②希望函数定义的更加松散灵活 包裹传参分两种:包裹位置传参和包裹关键字传参.先看包裹位置传参: 在这 ...
随机推荐
- 解决Eclipse中Android SDK Manager图标不见了的问题
在Eclipse中安装完ADT后,发现 Android SDK Manager图标不见了,Android Virtual Device Manager图标也不见了. 解决这个问题,可用如下方法: 打开 ...
- 【c++】动态绑定
C++的函数调用默认不使用动态绑定.要触发动态绑定,必须满足两个条件: 只有指定为虚函数的成员函数才能进行动态绑定 必须通过基类类型的引用或指针进行函数调用 因为每个派生类对象中都拥有基类部分,所以可 ...
- java POST 传值 加签 验证
话不多说,代码如下 package com.syl.test_key; import lombok.extern.slf4j.Slf4j; import org.apache.commons.code ...
- B/S结构中页面间的传值
常见的页面间的传值有session,cookie,application,server.transfer(),queryString,今天主要记录一下server.transfer()的用法. 从A页 ...
- 那些年的Java学习笔记
1.1L是什么意思??L表示long ,long占用8个字节,表示范围:-9223372036854775808 ~ 9223372036854775807 1l就是1. 2.alt+shift+j ...
- 此请求的URL的长度超过配置的maxUrlLength值
aps.net 网站的url长度默认限制为260个字符. 修改web.config即可 <system.web> <httpRuntime maxUrlLength=" ...
- CentOS 启动-运行级别
Linux系统的启动过程:内核的引导 > 运行init > 系统初始化 > 建立终端 > 用户登录系统 运行init init 进程是系统所有进程的起点: 主要功能: 准备软件 ...
- mysql-connector/python使用示例
1.下载安装connector/python 地址:https://dev.mysql.com/downloads/connector/python/ 下载的版本(mysql-connector-py ...
- Uva 1378 - A Funny Stone Game
1378 - A Funny Stone Game Time limit: 3.000 seconds The funny stone game is coming. There are n pile ...
- powerdesigner 将表中name列值复制到comment列 (保留原有comment)
/** * PowerDesigner里面将表中name列值复制到comment列 * @see --------------------------------------------------- ...