Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:12562 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1505 invoked by uid 1010); 3 Sep 2004 15:04:03 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 68080 invoked by uid 1007); 3 Sep 2004 14:54:58 -0000 Message-ID: <20040903145458.68064.qmail@pb1.pair.com> To: internals@lists.php.net Date: Fri, 03 Sep 2004 16:54:56 +0200 User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable X-Posted-By: 217.85.192.53 Subject: Writeing OO exteions for PHP 4.3 From: jan.gerritsen@michel-consulting.de (Jan Gerritsen) Hello, I want to write an OO extension in C++ for my PHP 4.3.8 under linux. I have already written some extensions in C for my own purposes, which introduce new functions to PHP. Studying the sources of ext/standard/dir.c, ext/ming/ming.c and the tutorial from J Smith (http://bugs.tutorbuddy.com/phpcpp/phpcpp/) I got already this far: I have managed to build and link the CPP sources as a shared object which can be loaded and called from PHP. I have introduced the new class to PHP using the following code in the PHP_MINIT_FUNCTION of my extension: static zend_class_entry *url_class_entry_ptr; static int le_url; function_entry url_class_functions[] =3D { PHP_FALIAS(url, url_init, NULL) PHP_FALIAS(set_string, url_set_string, NULL) {NULL, NULL, NULL} }; static ZEND_RSRC_DTOR_FUNC(destroy_url) { if (rsrc->ptr) { delete (Url_class*) rsrc->ptr; rsrc->ptr =3D NULL; } } PHP_MINIT_FUNCTION(url) { zend_class_entry url_class_entry; INIT_CLASS_ENTRY(url_class_entry, "url", url_class_functions); url_class_entry_ptr =3D zend_register_internal_class(&url_class_entry TSRMLS_CC); le_url =3D zend_register_list_destructors_ex(destroy_url, NULL, "url", module_number); return SUCCESS; } This class can be created, and the functions (methods) can be called from PHP. Example: $url =3D new URL(); $url->set_string("12345"); Now my problem is, how can I save the pointer of my C++ class, created in the url_init function, and restore it in the other functions/methods: PHP_FUNCTION(url_init) { Url_class * url =3D new Url_class; =09 / * code to save the address of url */ } PHP_FUNCTION(url_set_string) { Url_class *url =3D NULL; /* code to fetch url */ =09 if( url !=3D NULL ) { url->set_string(=93test=94); RETURN_TRUE; } RETURN_FALSE; } I could not work out how to do this, by studying the code of the OO extensions I mentioned. Can someone give me a hint, ore some example code, how to do such things?= thanks Jan Gerritsen