call_user_function() in PHP4

From: Date: Fri, 28 Apr 2000 16:50:26 +0000
Subject: call_user_function() in PHP4
Groups: php.version4 
Request: Send a blank email to php-version4+get-14151@lists.php.net to get a copy of this message
Hi all, I'm hoping someone here can help me with this problem. I've been trying to fix up php_pam (ftp://ftp.netexpress.net/pub/pam) to work with PHP4. Everything seems to work just fine, except for one section of code where I'm calling a user function from within PHP: { pval conv_retval, msg_pval, resp_pval; pval *args[2]; if (array_init(&msg_pval) == FAILURE) { php3_error( E_ERROR, "Couldn't initialize pam message array" ); return PAM_CONV_ERR; } if (array_init(&resp_pval) == FAILURE) { php3_error( E_ERROR, "Couldn't initialize pam response array" ); return PAM_CONV_ERR; } for (count=0; count < num_msg; ++count) { add_next_index_long( &msg_pval, msgm[count]->msg_style ); add_next_index_string( &msg_pval, msgm[count]->msg, 1 ); } args[0] = &msg_pval; args[1] = &resp_pval; if (call_user_function( CG(function_table), NULL, &php_conv_func, &conv_retval, 2, args ) != SUCCESS) { goto failed_conversation; } ... } The second argument passed to the user function, resp_pval, is a pass-by-reference which is used to return an array of values. This works fine in PHP3, but in PHP4, any attempt to reference the contents of resp_pval results in a segfault because the array has already been destroyed using efree(). I've seen many examples in the PHP4 code where reference counts are used on pvals (or rather zvals), and I've tried several ways to increment the refcount so that the array isn't freed, but with no success. Nor can I find any examples in the PHP4 code where call_user_function() is used with a function that returns information in this way. Does anybody know what I'm doing wrong? Am I simply better off rewriting the code so that all the information I need is returned in a single array as the user function's return value? TIA, Steve Langasek postmodern programmer

« previous php.version4 (#14151) next »