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" <rricha...@ctindustries.net> a écrit dans le message de news: 
49635ee5.3040...@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
> 



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to