Proper implementation of is_callback() & is_callable(). First one only performs a check if variable type is callback, while the second checks if function exists and if can be called.
The build was successful.
Details
The build was successful.
Details
This commit is contained in:
parent
65e38a364d
commit
d8f9db8f9a
|
@ -1937,6 +1937,13 @@ int ph7_value_is_callable(ph7_value *pVal) {
|
|||
rc = PH7_VmIsCallable(pVal->pVm, pVal, FALSE);
|
||||
return rc;
|
||||
}
|
||||
/*
|
||||
* [CAPIREF: ph7_value_is_callback()]
|
||||
* Please refer to the official documentation for function purpose and expected parameters.
|
||||
*/
|
||||
int ph7_value_is_callback(ph7_value *pVal) {
|
||||
return (pVal->iFlags & MEMOBJ_CALL) ? TRUE : FALSE;
|
||||
}
|
||||
/*
|
||||
* [CAPIREF: ph7_value_is_scalar()]
|
||||
* Please refer to the official documentation for function purpose and expected parameters.
|
||||
|
@ -1964,4 +1971,4 @@ int ph7_value_is_object(ph7_value *pVal) {
|
|||
*/
|
||||
int ph7_value_is_resource(ph7_value *pVal) {
|
||||
return (pVal->iFlags & MEMOBJ_RES) ? TRUE : FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,23 @@ static int PH7_builtin_is_bool(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
|||
ph7_result_bool(pCtx, res);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* bool is_callback($var)
|
||||
* Finds out whether a variable is a callback.
|
||||
* Parameters
|
||||
* $var: The variable being evaluated.
|
||||
* Return
|
||||
* TRUE if var is a callback. False otherwise.
|
||||
*/
|
||||
static int PH7_builtin_is_callback(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
int res = 0; /* Assume false by default */
|
||||
if(nArg > 0) {
|
||||
res = ph7_value_is_callback(apArg[0]);
|
||||
}
|
||||
/* Query result */
|
||||
ph7_result_bool(pCtx, res);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* bool is_char($var)
|
||||
* Finds out whether a variable is a character.
|
||||
|
@ -7388,6 +7405,7 @@ static const ph7_builtin_func aBuiltInFunc[] = {
|
|||
/* Variable handling functions */
|
||||
{ "is_array", PH7_builtin_is_array },
|
||||
{ "is_bool", PH7_builtin_is_bool },
|
||||
{ "is_callback", PH7_builtin_is_callback },
|
||||
{ "is_char", PH7_builtin_is_char },
|
||||
{ "is_float", PH7_builtin_is_float },
|
||||
{ "is_int", PH7_builtin_is_int },
|
||||
|
|
12
engine/vm.c
12
engine/vm.c
|
@ -5739,16 +5739,10 @@ PH7_PRIVATE int PH7_VmIsCallable(ph7_vm *pVm, ph7_value *pValue, int CallInvoke)
|
|||
* Parameters
|
||||
* $name
|
||||
* The callback function to check
|
||||
* $syntax_only
|
||||
* If set to TRUE the function only verifies that name might be a function or method.
|
||||
* It will only reject simple variables that are not strings, or an array that does
|
||||
* not have a valid structure to be used as a callback. The valid ones are supposed
|
||||
* to have only 2 entries, the first of which is an object or a string, and the second
|
||||
* a string.
|
||||
* Return
|
||||
* TRUE if name is callable, FALSE otherwise.
|
||||
*/
|
||||
static int vm_builtin_is_callback(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
static int vm_builtin_is_callable(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vm *pVm;
|
||||
int res;
|
||||
if(nArg < 1) {
|
||||
|
@ -5759,7 +5753,7 @@ static int vm_builtin_is_callback(ph7_context *pCtx, int nArg, ph7_value **apArg
|
|||
/* Point to the target VM */
|
||||
pVm = pCtx->pVm;
|
||||
/* Perform the requested operation */
|
||||
res = PH7_VmIsCallable(pVm, apArg[0], TRUE);
|
||||
res = PH7_VmIsCallable(pVm, apArg[0], FALSE);
|
||||
ph7_result_bool(pCtx, res);
|
||||
return SXRET_OK;
|
||||
}
|
||||
|
@ -10459,7 +10453,7 @@ static int vm_builtin_utf8_decode(ph7_context *pCtx, int nArg, ph7_value **apArg
|
|||
/* Table of built-in VM functions. */
|
||||
static const ph7_builtin_func aVmFunc[] = {
|
||||
{ "function_exists", vm_builtin_func_exists },
|
||||
{ "is_callback", vm_builtin_is_callback },
|
||||
{ "is_callable", vm_builtin_is_callable },
|
||||
{ "get_defined_functions", vm_builtin_get_defined_func },
|
||||
{ "register_autoload_handler", vm_builtin_register_autoload_handler },
|
||||
{ "register_shutdown_function", vm_builtin_register_shutdown_function },
|
||||
|
|
|
@ -641,6 +641,7 @@ PH7_APIEXPORT int ph7_value_is_float(ph7_value *pVal);
|
|||
PH7_APIEXPORT int ph7_value_is_bool(ph7_value *pVal);
|
||||
PH7_APIEXPORT int ph7_value_is_string(ph7_value *pVal);
|
||||
PH7_APIEXPORT int ph7_value_is_callback(ph7_value *pVal);
|
||||
PH7_APIEXPORT int ph7_value_is_callable(ph7_value *pVal);
|
||||
PH7_APIEXPORT int ph7_value_is_array(ph7_value *pVal);
|
||||
PH7_APIEXPORT int ph7_value_is_object(ph7_value *pVal);
|
||||
PH7_APIEXPORT int ph7_value_is_resource(ph7_value *pVal);
|
||||
|
|
Loading…
Reference in New Issue