# calling zend_eval_string

- Thread: https://externals.io/message/27225
- Original archive: https://news-web.php.net/php.internals/27225
- Started by Edsko de Vries on 2006-12-31T14:45:18+00:00
- Messages: 1
- 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

---

## #27225 — Edsko de Vries — 2006-12-31T14:45:18+00:00

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

Hi,

If I try to call zend_eval_string as follows:

zval* retval;
MAKE_STD_ZVAL(retval);
zend_eval_string("return 5;", retval, "eval'd code" TSRMLS_CC);

I get the following runtime error:

eval'd code(1) : Parse error - syntax error, unexpected `T_RETURN` 

It turns out that zend_eval_string actualy prepends "return " to the
argument to zend_eval_string (zend_execute_API.c, around line 1577),
causing "return return 5;" to be evaluated - hence the error. Why is
that the case? Is there a different function I could call that doesn't
do this? (The problem is that the code will be user-supplied, not
written by be; so to work-around this problem, I'd have to check if the
user-supplied code starts with "return "; if so, remove it, only for it
to be added again by zend_eval_string).

What is the proper solution to this problem?

Thanks in advance,

Edsko
