Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:12563 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42140 invoked by uid 1010); 3 Sep 2004 16:48:10 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 25543 invoked from network); 3 Sep 2004 16:43:04 -0000 Received: from unknown (HELO mail.communityconnect.com) (209.10.169.57) by pb1.pair.com with SMTP; 3 Sep 2004 16:43:04 -0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.communityconnect.com (Postfix) with ESMTP id 3EA5B6F5DD; Fri, 3 Sep 2004 12:47:50 -0400 (EDT) Received: from mail.communityconnect.com ([127.0.0.1]) by localhost (cc18-2.web.gbx.ccops.us [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 14817-16; Fri, 3 Sep 2004 12:47:46 -0400 (EDT) Received: from [192.168.101.34] (cc240-0.web.gbx.ccops.us [10.30.0.240]) by mail.communityconnect.com (Postfix) with ESMTP id 2DF006F5D6; Fri, 3 Sep 2004 12:47:46 -0400 (EDT) Reply-To: john@coggeshall.org To: Jan Gerritsen Cc: internals@lists.php.net In-Reply-To: <20040903145458.68064.qmail@pb1.pair.com> References: <20040903145458.68064.qmail@pb1.pair.com> Content-Type: text/plain; charset= Message-ID: <1094229635.17236.16.camel@unix-101-34.hq.communityconnect.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 (1.4.5-7) Date: Fri, 03 Sep 2004 12:40:37 -0400 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at mail.communityconnect.com Subject: Re: [PHP-DEV] Writeing OO exteions for PHP 4.3 From: john@coggeshall.org (John Coggeshall) If I understand you correctly you can put this pointer inside of a resource container and return the resource container to user space as the return value from url_init(). Then, from url_set_string() you accept the resource as a parameter and extract the pointer to your CPP instance of whatever class. John On Fri, 2004-09-03 at 10:54, Jan Gerritsen wrote: > 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[] = { > 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 = 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 = zend_register_internal_class(&url_class_entry > TSRMLS_CC); > > le_url = 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 = 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 = new Url_class; > > / * code to save the address of url */ > } > > PHP_FUNCTION(url_set_string) > { > Url_class *url = NULL; > > /* code to fetch url */ > > if( url != NULL ) { > url->set_string(“test”); > 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