php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65410 Add call_func() syntax
Submitted: 2013-08-07 08:27 UTC Modified: 2015-04-15 14:00 UTC
From: hark110 at 163 dot com Assigned: cmb (profile)
Status: Closed Package: Performance problem
PHP Version: 5.5.1 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hark110 at 163 dot com
New email:
PHP Version: OS:

 

 [2013-08-07 08:27 UTC] hark110 at 163 dot com
Description:
------------
now php use call_user_func_array() function dynamic call other function of unsure paramters,  but the function performance slow than $function() call function and about 50%, but variable functions can not call dynamic paramters
other, call_user_func() and call_user_func_array() can not call protected and private method of object
so i think php add call_func syntax instead call function ways
	
my think is below, use foreach pcode comply SEND_VAR to function:
1. Zend/zend_language_scanner.l add code:

<ST_IN_SCRIPTING>"call_func" {
    return T_CALL_FUNC;
}

2.Zend/zend_language_parser.y add code:
find **function_call:** section append code:

 |   T_CALL_FUNC '(' call_function_name function_call_array_parameters ')' 
    { zend_do_end_function_call(&$3, &$$, &$4, 0, 1 TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C);}

then add:

call_function_name:
    variable {zend_do_end_variable_parse(&$3, BP_VAR_R, 0 TSRMLS_CC);zend_do_begin_dynamic_function_call(&$3, 0 TSRMLS_CC);}
    |   T_STRING {$$=$3;zend_do_begin_dynamic_function_call(&$3, 0 TSRMLS_CC);}
;
function_call_array_parameter:
        { Z_LVAL($$.u.constant)=0; }
    |   expr {zend_do_pass_array_parameters(&$4, ZEND_SEND_VAL, Z_LVAL($$.u.constant) TSRMLS_CC)} 
;

3.Zend/zend_compile.c add zend_do_pass_array_parameters() function:

void zend_do_pass_array_parameters(znode * expr, zend_uchar op, int offset TSRMLS_DC) /* {{{ */ {

    zend_op *opline;
    znode last_container;
    znode *result;
    expr->u.opline_num = get_next_op_number(CG(active_op_array));

    opline = get_next_op(CG(active_op_array) TSRMLS_CC);

    /* Preform array reset */
    opline->opcode = ZEND_FE_RESET;
    opline->result.op_type = IS_VAR;
    opline->result.u.var = get_temporary_variable(CG(active_op_array));
    opline->op1 = *array;
    SET_UNUSED(opline->op2);
    opline->extended_value = is_variable ? ZEND_FE_RESET_VARIABLE : 0;

    dummy_opline.result = opline->result;

    zend_stack_push(&CG(foreach_copy_stack), (void *) &dummy_opline, sizeof (zend_op));

    /* save the location of FE_FETCH */
    //as_token->u.opline_num = get_next_op_number(CG(active_op_array));

    opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    opline->opcode = ZEND_FE_FETCH;
    opline->result.op_type = IS_VAR;
    opline->result.u.var = get_temporary_variable(CG(active_op_array));
    opline->op1 = dummy_opline.result;
    opline->extended_value = 0;
    SET_UNUSED(opline->op2);

    opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    opline->opcode = ZEND_OP_DATA;
    result = opline->result;
    zend_do_pass_param(result, op, offset TSRMLS_CC);
    SET_UNUSED(opline->op1);
    SET_UNUSED(opline->op2);
    SET_UNUSED(opline->result);
    zend_do_foreach_end(expr)
}






Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-05 17:40 UTC] willfitch@php.net
What's wrong with approaching this with Reflection?  You can even change the visibility to achieve what you're referring to, and bypass the dynamic call_user* functions.
 [2015-04-15 14:00 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2015-04-15 14:00 UTC] cmb@php.net
This issue has been addressed by the introduction of argument
unpacking in PHP 5.6.0[1].

[1] <http://php.net/manual/en/migration56.new-features.php#migration56.new-features.splat>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 14:01:31 2024 UTC