[php-src] Issue #12536: Embedded api question: zend_catch not working?
| From: | chibinz | Date: | Fri, 27 Oct 2023 10:55:47 +0000 |
| Subject: | [php-src] Issue #12536: Embedded api question: zend_catch not working? | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245668@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12536
Author: chibinz
### Description
Hi,
I am trying to create a small application embedding a php interpreter, but somehow it's not
working as expected (zend_catch not catching an explicitly thrown exception). I compiled php with
clang -g and the following configure options:
```
./configure --prefix=$targetdir/php-$suffix \
--disable-all \
--disable-cgi \
--disable-shared \
--enable-static \
--enable-debug-assertions \
--enable-option-checking=fatal \
--enable-embed=static \
--enable-calendar=static \
--enable-ctype=static \
--enable-filter=static \
--enable-phar=static \
--enable-tokenizer=static \
--enable-fileinfo=static \
--enable-shmop=static \
--enable-sockets=static \
--enable-posix=static \
--enable-session=static \
--enable-opcache=static \
--enable-fuzzer \
--without-pcre-jit \
--with-pic
```
The application C code:
```
#include "sapi/embed/php_embed.h"
int main(int argc, char **argv)
{
PHP_EMBED_START_BLOCK(argc, argv)
zval a;
int retval = 0;
zend_try {
retval = zend_eval_string("throw new Exception('qwerty');", &a,
"example");
} zend_catch {
printf("exception\n");
} zend_end_try();
printf("retval: %d\n", retval);
PHP_EMBED_END_BLOCK()
}
```
Resulted in this output:
```
retval: 0
[Fri Oct 27 10:20:17 2023] Script: '-'
/tmp/php-aflplusplus/Zend/zend_objects.c(186) : Freeing 0x00007f819d45e0c0 (152 bytes), script=-
=== Total 1 memory leaks detected ===
```
But I expected this output instead:
```
exception
retval: -1
```
Also, I wonder if there's any documentation on internal zend_* functions for embedding php
within another c application?
Thanks in advance!
### PHP Version
php-8.2.7RC1
### Operating System
Ubuntu 22.04