Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:12567 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98329 invoked by uid 1010); 3 Sep 2004 18:35:12 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 90702 invoked by uid 1007); 3 Sep 2004 18:34:10 -0000 Message-ID: <20040903183410.90659.qmail@pb1.pair.com> To: internals@lists.php.net Date: Fri, 03 Sep 2004 20:33:51 +0200 User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 References: <20040903145458.68064.qmail@pb1.pair.com> <1094229635.17236.16.camel@unix-101-34.hq.communityconnect.com> In-Reply-To: <1094229635.17236.16.camel@unix-101-34.hq.communityconnect.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable X-Posted-By: 217.85.192.53 Subject: Re: [PHP-DEV] Writeing OO exteions for PHP 4.3 From: artur@gmx.net (Jan Gerritsen) Hi, > 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 accep= t > the resource as a parameter and extract the pointer to your CPP instanc= e > of whatever class. Tanks for your response, but your solution do not work for me, because I = don=92t get the resource_id as parameter for calls to the object.=20 ($php_url_object->set_string(=93asdf=94); ) I now save the C++ Object pointer in a resource and save this resource=20 as an attribute of the PHP object. PHP_FUNCTION(url_init) { Url_class * url =3D new Url_class; zval * this_p =3D getThis(); MAKE_STD_ZVAL(return_value); int res_id =3D ZEND_REGISTER_RESOURCE(NULL, url, le_url); add_property_resource(getThis(), "url_class_ressource", res_id); } It=92s a little bit tricky to extract this resource and the inherit=20 pointer again, like I do in my set_string function: PHP_FUNCTION(url_set_string) { zval ** ressource; if( zend_hash_find(getThis()->value.obj.properties, "url_class_ressource", sizeof("url_class_ressource"), (void**) &ressource) =3D=3D FAILURE ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find url_class_ressource"); RETURN_FALSE; } if( ressource =3D=3D NULL || (*ressource) =3D=3D NULL ||(*ressource)->type !=3D IS_RESOURCE ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Ressource not found"); RETURN_FALSE; } Url_class * url; url =3D (Url_class *) zend_fetch_resource(ressource TSRMLS_CC, -1, "url", NULL, 1, le_url); ZEND_VERIFY_RESOURCE(url); if( url =3D=3D NULL ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Ressource is invalid???"); RETURN_FALSE; } if(url->setString("test")) { RETURN_TRUE; } RETURN_FALSE; } But I don=92t get memory leeks, because php makes sure my resource is=20 destructed if it is not referenced anymore: static ZEND_RSRC_DTOR_FUNC(destroy_url) { Url_class * url =3D (Url_class *) rsrc->ptr;; delete url; } I am not to happy with this solution, because the user can access the=20 "url_class_ressource" attribute of the PHP url Object, but this will=20 work for now. Or can someone give me better solution? I am happy for everything which=20 may help me,=85 Greets Jan