Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37027 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84005 invoked from network); 15 Apr 2008 15:37:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Apr 2008 15:37:24 -0000 Authentication-Results: pb1.pair.com header.from=magreenblatt@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=magreenblatt@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.204.227 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: magreenblatt@gmail.com X-Host-Fingerprint: 72.14.204.227 qb-out-0506.google.com Received: from [72.14.204.227] ([72.14.204.227:12535] helo=qb-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 64/04-62008-3BBC4084 for ; Tue, 15 Apr 2008 11:37:23 -0400 Received: by qb-out-0506.google.com with SMTP id e11so2550654qbe.15 for ; Tue, 15 Apr 2008 08:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=gmBg5I+QhkY8te4KYBKHk14M8xOMe/Fi1HTeH3kR2WQ=; b=AIpUQ1xBXAS3hjWXtHBL8kSEQHm3bmyGMu5UGePI1DgQEbdXAiyK871I4ySNgDlgnQ0Byz7JUW11OVGenfwpW6KB+7JGHxuEO11lQwVUJBZkAnHcj6Izde2igKOXvozd0nkmv4M8L/9VftVpZcMbA2qJp5BosH932KDQEb8IuUk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=tLKSlZe4JkD6WlAjrM4+NJ6Ps+SNVvafmIyff6CoeKdRTecXnncIkyiwjULiZ6b+ERISChovfo2yOaHVR6yk2n8R4wMpCxb49mLmXdVoYM7+/eaMZf6kttrjlKSzTc1POPRBrc0vEn/cNL44J5usCB3JEhCtiqqYHJvR40IXaXE= Received: by 10.115.95.1 with SMTP id x1mr8370106wal.122.1208273839903; Tue, 15 Apr 2008 08:37:19 -0700 (PDT) Received: by 10.114.149.15 with HTTP; Tue, 15 Apr 2008 08:37:17 -0700 (PDT) Message-ID: Date: Tue, 15 Apr 2008 11:37:17 -0400 To: internals@lists.php.net MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_29929_2249716.1208273839897" Subject: calling a script function via call_user_function From: magreenblatt@gmail.com ("Marshall Greenblatt") ------=_Part_29929_2249716.1208273839897 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All, I'm building an embedded application that uses PHP scripting for internal data processing. It behaves as follows: 1. Provide arbitrary application-specified input parameters. 2. Execute a PHP script that manipulates those input parameters. 3. Retrieve the resulting return value. I've attempted three possible approaches for achieving this goal. Please bear with me as I explain each of these approaches -- it's necessary in order to understand the question :-) Approach A: Parse a script containing a PHP function, and then call that PHP function. On the PHP side: // some arbitrary user-defined PHP function function myfunction( $pArg ) { return strtoupper( $pArg ); } On the application side: // do something to parse "myfunction" and cause it to be available via call_user_function() php_lint_script(&file_handle TSRMLS_CC); zval funcname, retval; zval *args[1]; INIT_ZVAL(retval); INIT_ZVAL(funcname); MAKE_STD_ZVAL(args[1]); ZVAL_STRING(args[1], "the string to make uppercase", 0); ZVAL_STRING(&funcname, "myfunction", 0); // call the user function if(call_user_function(EG(function_table), NULL, &funcname, &retval, 1, args TSRMLS_CC) != FAILURE) { // it worked } My problem with Approach A is that "php_lint_script", "php_execute_script", etc, do not add the PHP function "myfunction" to the EG(function_table) hash, so call_user_function() always fails. Approach B: Execute a PHP script and retrieve the return value without calling a particular PHP function. On the PHP side: return strtoupper( $GLOBAL_VARIABLE ); On the application side: php_register_variable("GLOBAL_VARIABLE", "the string to make uppercase", NULL TSRMLS_CC); zval *retval; php_execute_simple_script(&file_handle, &retval TSRMLS_CC); My problem with Approach B is that the return zval from the php_execute_simple_script() function always contains a true/false value instead of whatever was returned using the 'return' construct from the code. Approach C: Similar to approach B, except call a module function to record the result. On the PHP side: record_return( strtoupper( $GLOBAL_VARIABLE ) ); On the application side, create a module that provides the "record_return" function to record the return value for later usage. This approach works. However, if at all possible, I would prefer to use the PHP language 'return' construct and somehow retrieve the resulting value. Does anyone have any suggestions on how I could get either approach A or approach B working? Any input would be greatly appreciated. I'm currently using PHP 5.2.4 for development -- I can upgrade to a newer version if that would be beneficial. Thanks, Marshall ------=_Part_29929_2249716.1208273839897--