Req #65410 [Opn->Csd]: Add call_func() syntax
| From: | cmb@php.net | Date: | Wed, 15 Apr 2015 14:00:44 +0000 |
| Subject: | Req #65410 [Opn->Csd]: Add call_func() syntax | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-192101@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65410&edit=1
ID: 65410
Updated by: cmb@php.net
Reported by: hark110 at 163 dot com
Summary: Add call_func() syntax
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Performance problem
Operating System: All
PHP Version: 5.5.1
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2013-11-05 17:40:25] 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.
------------------------------------------------------------------------
[2013-08-07 08:27:37] 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)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65410&edit=1