# Help with calling PHP functions

- Thread: https://externals.io/message/37246
- Original archive: https://news-web.php.net/php.internals/37246
- Started by Dhiru Pandey on 2008-04-26T18:23:03+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

---

## #37246 — Dhiru Pandey — 2008-04-26T18:23:03+00:00

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

[My apologies if I am posting on the wrong group...please point me to 
the right one]

I am trying to figure out a way to invoke PHP functions directly i.e. 
bypassing the PHP compiler (scanner and parser). For now it would be
great if I can get some help calling them from C. Ultimately I would 
like to call them from Java.

For e.g. I would like to call:

PHP_FUNCTION(str_repeat)

It appears to me when stepping thru the invocation path that some 
compiler and executor globals need to be initialized before one can
call these functions. In its raw form these functions do not have the
arguments (needed by the function) passed as parameters to the functions 
call. I need some guidance in this area and recommendations on how to do 
this

Thanks in advance
-Dhiru

---

## #37247 — Edward Z. Yang — 2008-04-26T18:45:45+00:00

URL: https://externals.io/message/37246#37247 · In reply to: #37246

Dhiru Pandey wrote:
> I am trying to figure out a way to invoke PHP functions directly i.e.
> bypassing the PHP compiler (scanner and parser). For now it would be
> great if I can get some help calling them from C. Ultimately I would
> like to call them from Java.

It's not difficult to call PHP_FUNCTIONs if you're inside PHP: you
create a zval with the appropriate callback value (a string if you're
dealing with global PHP functions) and then use call_user_function. You
can find detailed instructions here:
http://www.php.net/~wez/extending-php.pdf

Can't help you for the other, although "Extending and Embedding PHP" by
Sara Golemon, George Schlossnagle and Wez Furlong covers that topic, I
think.

-- 
 Edward Z. Yang                        GnuPG: 0x869C48DA
 HTML Purifier <http://htmlpurifier.org> Anti-XSS Filter
 [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]

---

## #37248 — Dhiru Pandey — 2008-04-26T19:15:52+00:00

URL: https://externals.io/message/37246#37248 · In reply to: #37247

Thanks for responding.

May be I mis-wrote.
What I would really like is a way to call the native c functions of the php implementation directly (bypassing the PHP compiler) like:

PHP_FUNCTION(str_repeat)
PHP_FUNCTION(addcslashes)  etc.

In other words I would like to invoke this functions directly thru C or Java.

I do not want to callback into a PHP script user function

Thanks,
-Dhiru


Edward Z. Yang wrote:
> Dhiru Pandey wrote:
> > […]
> 
> It's not difficult to call PHP_FUNCTIONs if you're inside PHP: you
> create a zval with the appropriate callback value (a string if you're
> dealing with global PHP functions) and then use call_user_function. You
> can find detailed instructions here:
> http://www.php.net/~wez/extending-php.pdf
> 
> Can't help you for the other, although "Extending and Embedding PHP" by
> Sara Golemon, George Schlossnagle and Wez Furlong covers that topic, I
> think.

---

## #37250 — Edward Z. Yang — 2008-04-26T19:51:59+00:00

URL: https://externals.io/message/37246#37250 · In reply to: #37248

Dhiru Pandey wrote:
> Thanks for responding.
> 
> May be I mis-wrote.
> What I would really like is a way to call the native c functions of the
> php implementation directly (bypassing the PHP compiler) like:
> 
> PHP_FUNCTION(str_repeat)
> PHP_FUNCTION(addcslashes)  etc.
> 
> In other words I would like to invoke this functions directly thru C or
> Java.
> 
> I do not want to callback into a PHP script user function

Callback works with the native C functions too. It'll be pretty nasty
trying to get all of PHP's macros to work from scratch. Just use the
infrastructure that's in place already.

-- 
 Edward Z. Yang                        GnuPG: 0x869C48DA
 HTML Purifier <http://htmlpurifier.org> Anti-XSS Filter
 [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]

---

## #37252 — Edward Z. Yang — 2008-04-26T19:52:43+00:00

URL: https://externals.io/message/37246#37252 · In reply to: #37250

Edward Z. Yang wrote:
> Callback works with the native C functions too. It'll be pretty nasty
> trying to get all of PHP's macros to work from scratch. Just use the
> infrastructure that's in place already.

Sorry about the double-post; I should clarify: I mean that callback
works with PHP functions that were implemented in C.

-- 
 Edward Z. Yang                        GnuPG: 0x869C48DA
 HTML Purifier <http://htmlpurifier.org> Anti-XSS Filter
 [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]

---

## #37253 — Nathan Nobbe — 2008-04-26T20:08:33+00:00

URL: https://externals.io/message/37246#37253 · In reply to: #37246

> [My apologies if I am posting on the wrong group...please point me to the
> right one]
>
> I am trying to figure out a way to invoke PHP functions directly i.e.
> bypassing the PHP compiler (scanner and parser). For now it would be
> great if I can get some help calling them from C. Ultimately I would like
> to call them from Java.


per calling them from java you might use or investigate the quercus or 'ibm
project 0' projects.  they might not be what you want as they are separate
java-based implementations of php, but im guessing you can access php
through them; or at any rate the java equivalent, but they dont really say
that explicitly.
http://www.caucho.com/resin-3.0/quercus/#Java-Users

-nathan
