FAQ
Hello all,

here's what I'm trying to do: I'm writing a PHP extension in C and I'd like
to create a DOMDocument object in my C code that I could send back to my PHP
code. I have been trying many things, like:

#include "ext/dom/php_dom.h"

....

zval *doc;
MAKE_STD_ZVAL(doc);
object_init_ex(doc, dom_document_class_entry);
zval c_ret, constructor;
INIT_ZVAL(c_ret);
INIT_ZVAL(constructor);

ZVAL_STRING(&constructor, ZEND_CONSTRUCTOR_FUNC_NAME, 1);
call_user_function(NULL, &doc, &constructor, &c_ret, 0, NULL TSRMLS_CC);

It compiles, but when I call my function, it fails on object_init_ex (and
when I say it fails, it stops apache...). I've also tried things like:

zend_call_method(NULL, dom_document_class_entry,
dom_document_class_entry->constructor, ZEND_CONSTRUCTOR_FUNC_NAME,
strlen(ZEND_CONSTRUCTOR_FUNC_NAME), &doc, 2, "1.0", "UTF-8" TSRMLS_CC);

but it stills kill apache each time.

Does anyone know how to do this? Is this even feasible?

Regards,

François Lemaire

Search Discussions

  • Rob Richards at Jan 6, 2009 at 1:39 pm

    François Lemaire wrote:
    Hello all,

    here's what I'm trying to do: I'm writing a PHP extension in C and I'd like
    to create a DOMDocument object in my C code that I could send back to my PHP
    code. I have been trying many things, like:

    #include "ext/dom/php_dom.h"

    ....

    zval *doc;
    MAKE_STD_ZVAL(doc);
    object_init_ex(doc, dom_document_class_entry);
    zval c_ret, constructor;
    INIT_ZVAL(c_ret);
    INIT_ZVAL(constructor);

    ZVAL_STRING(&constructor, ZEND_CONSTRUCTOR_FUNC_NAME, 1);
    call_user_function(NULL, &doc, &constructor, &c_ret, 0, NULL TSRMLS_CC);

    It compiles, but when I call my function, it fails on object_init_ex (and
    when I say it fails, it stops apache...). I've also tried things like:

    zend_call_method(NULL, dom_document_class_entry,
    dom_document_class_entry->constructor, ZEND_CONSTRUCTOR_FUNC_NAME,
    strlen(ZEND_CONSTRUCTOR_FUNC_NAME), &doc, 2, "1.0", "UTF-8" TSRMLS_CC);

    but it stills kill apache each time.

    Does anyone know how to do this? Is this even feasible?
    Include dom/xml_common.h and use the DOM_RET_OBJ macro.
    That will make sure everything is created properly. You should be able
    to find an example of this in the xsl extension.

    Rob
  • François Lemaire at Jan 6, 2009 at 4:22 pm
    Thanks, after some more searching in the direction you pointed, it works in
    a function of my extension.

    Now I have another problem, which is trickier I think; in the same
    extension, I'd like to have the possibility to call some PHP code from my
    PHP_MINIT_FUNCTION and I'd like to pass a DOMDocument to this PHP code (I
    need to initialize some things in my extension, and as an extension
    mechanism for my own extension, I'd like to give the possibility to add
    initialization code written in PHP to launch during my extension's
    initialization). I know this is possible in a function by creating the
    variable, registering it into the PHP global area, and using the
    zend_eval_string function. But if I use the exact same code as in the
    function to create my DOMDocument, it fails when I use php_dom_create_object
    (which is hidden behind the DOM_RET_OBJ macro) and it fails whenever I try
    to use zend_eval_string, even for the most trivial PHP code. Is it possible
    to call some PHP code from my PHP_MINIT_FUNCTION?

    Regards,

    François Lemaire

    "Rob Richards" <rrichards@ctindustries.net> a écrit dans le message de news:
    49635EE5.3040103@ctindustries.net...
    François Lemaire wrote:
    Hello all,

    here's what I'm trying to do: I'm writing a PHP extension in C and I'd
    like
    to create a DOMDocument object in my C code that I could send back to my
    PHP
    code. I have been trying many things, like:

    #include "ext/dom/php_dom.h"

    ....

    zval *doc;
    MAKE_STD_ZVAL(doc);
    object_init_ex(doc, dom_document_class_entry);
    zval c_ret, constructor;
    INIT_ZVAL(c_ret);
    INIT_ZVAL(constructor);

    ZVAL_STRING(&constructor, ZEND_CONSTRUCTOR_FUNC_NAME, 1);
    call_user_function(NULL, &doc, &constructor, &c_ret, 0, NULL TSRMLS_CC);

    It compiles, but when I call my function, it fails on object_init_ex (and
    when I say it fails, it stops apache...). I've also tried things like:

    zend_call_method(NULL, dom_document_class_entry,
    dom_document_class_entry->constructor, ZEND_CONSTRUCTOR_FUNC_NAME,
    strlen(ZEND_CONSTRUCTOR_FUNC_NAME), &doc, 2, "1.0", "UTF-8" TSRMLS_CC);

    but it stills kill apache each time.

    Does anyone know how to do this? Is this even feasible?
    Include dom/xml_common.h and use the DOM_RET_OBJ macro.
    That will make sure everything is created properly. You should be able to
    find an example of this in the xsl extension.

    Rob

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedJan 6, '09 at 1:30p
activeJan 6, '09 at 4:22p
posts3
users2
websitephp.net

2 users in discussion

François Lemaire: 2 posts Rob Richards: 1 post

People

Translate

site design / logo © 2022 Grokbase