# call user defined function with args

- Thread: https://externals.io/message/60327
- Original archive: https://news-web.php.net/php.internals/60327
- Started by Yader Hernandez on 2012-04-27T04:43:23+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #60327 — Yader Hernandez — 2012-04-27T04:43:23+00:00

URL: https://externals.io/message/60327#60327

Hello,

I found this zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache
*fci_cache TSRMLS_DC) and many examples using it. I can successfully call
this and it will call the user function for me. I'm interested in learning
how to not only call the function, but also pass arguments to that function.

Can anyone please point me to where I can see how that's done?

thx

---

## #60329 — Laruence — 2012-04-27T06:51:10+00:00

URL: https://externals.io/message/60327#60329 · In reply to: #60327

Hi:
  you can refer to zif_call_user_func, which could be find at
http://lxr.php.net/opengrok/xref/PHP_5_4/ext/standard/basic_functions.c#4714

thanks

On Fri, Apr 27, 2012 at 12:43 PM, Yader Hernandez
<yader.hernandez@gmail.com> wrote:
> Hello,
>
> I found this zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache
> *fci_cache TSRMLS_DC) and many examples using it. I can successfully call
> this and it will call the user function for me. I'm interested in learning
> how to not only call the function, but also pass arguments to that function.
>
> Can anyone please point me to where I can see how that's done?
>
> thx



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #60330 — jpauli — 2012-04-27T08:06:19+00:00

URL: https://externals.io/message/60327#60330 · In reply to: #60329

You might be interested by zend_call_method_with_[XXX]_params() as
well http://lxr.php.net/xref/PHP_5_3/Zend/zend_interfaces.h

Julien.Pauli


> Hi:
>  you can refer to zif_call_user_func, which could be find at
> http://lxr.php.net/opengrok/xref/PHP_5_4/ext/standard/basic_functions.c#4714
>
> thanks
>
> On Fri, Apr 27, 2012 at 12:43 PM, Yader Hernandez
> <yader.hernandez@gmail.com> wrote:
> > […]
>
>
>
> --
> Laruence  Xinchen Hui
> http://www.laruence.com/

---

## #60355 — Yader Hernandez — 2012-04-28T21:49:04+00:00

URL: https://externals.io/message/60327#60355 · In reply to: #60330

> You might be interested by zend_call_method_with_[XXX]_params() as
> well http://lxr.php.net/xref/PHP_5_3/Zend/zend_interfaces.h
>
> Julien.Pauli
>
> 
> > […]
> http://lxr.php.net/opengrok/xref/PHP_5_4/ext/standard/basic_functions.c#4714
> > […]
> zend_fcall_info_cache
> > […]
> call
> > […]
> learning
> > […]
> function.
> > […]
>

I had a look at
http://lxr.php.net/opengrok/xref/PHP_5_4/ext/standard/basic_functions.c#4714
and
I don't understand how it's passing the arguments into the closure given by
the user.

I can successfully call the closure given, but passing arguments into the
closure is something I'm not clear on.

Can someone please shed some light?

---

## #60356 — Nikita Popov — 2012-04-28T22:15:57+00:00

URL: https://externals.io/message/60327#60356 · In reply to: #60355

On Sat, Apr 28, 2012 at 11:49 PM, Yader Hernandez
<yader.hernandez@gmail.com> wrote:
> I had a look at
> http://lxr.php.net/opengrok/xref/PHP_5_4/ext/standard/basic_functions.c#4714
> and
> I don't understand how it's passing the arguments into the closure given by
> the user.
>
> I can successfully call the closure given, but passing arguments into the
> closure is something I'm not clear on.
>
> Can someone please shed some light?

Look at the zend_parse_parameters call. It fetches the params into
fci.params and their number into fci.param_count.

zend_fcall_info.params is defined as zval***, so it's basically an
array of zval**. So you simply have to create one with your arguments
:)

Hope that helps,
Nikita

---

## #60357 — Yader Hernandez — 2012-04-28T22:41:29+00:00

URL: https://externals.io/message/60327#60357 · In reply to: #60356

On Sat, Apr 28, 2012 at 3:15 PM, Nikita Popov <nikita.ppv@googlemail.com>wrote:

> On Sat, Apr 28, 2012 at 11:49 PM, Yader Hernandez
> <yader.hernandez@gmail.com> wrote:
> > […]
> http://lxr.php.net/opengrok/xref/PHP_5_4/ext/standard/basic_functions.c#4714
> > […]
> by
> > […]
>
> Look at the zend_parse_parameters call. It fetches the params into
> fci.params and their number into fci.param_count.
>
> zend_fcall_info.params is defined as zval***, so it's basically an
> array of zval**. So you simply have to create one with your arguments
> :)
>
> Hope that helps,
> Nikita
>

Ah! Great it works now. Thanks!

I'm assuming that return_value in this case is being used as whatever the
closure returned  ?

ie. function ($element) { return false; }

then that means I can do Z_LVAL_P(return_value) /* 0 */, correct ?
