Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43141 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28235 invoked from network); 21 Feb 2009 12:19:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Feb 2009 12:19:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:59795] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 33/E7-62765-351FF994 for ; Sat, 21 Feb 2009 07:19:31 -0500 Received: from MBOERGER-ZRH.ad.corp.google.com (12-90.107-92.cust.bluewin.ch [92.107.90.12]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 92F5F11F039; Sat, 21 Feb 2009 13:19:27 +0100 (CET) Date: Sat, 21 Feb 2009 13:16:36 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1836161691.20090221131636@marcus-boerger.de> To: "Matthew C. Rice" CC: internals@lists.php.net In-Reply-To: References: <7dd2dc0b0902201341q61230fcavfc9fdc9f42383289@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Adding/Updating ZVal Arrays to Object From: helly@php.net (Marcus Boerger) Hello Matthew, I gave a bunch of tutorials on this with various other folks, Johannes, Sara, Wez. The slides from November 2007 are still up and contain probably more information than you ever wanted to know. There is also the demo extension that you can access through cvs. http://talks.somabo.de/200711_php_code_camp.pdf http://talks.somabo.de/200711_php_code_camp.pps http://cvs.php.net/viewvc.cgi/pecl/demoext/ Friday, February 20, 2009, 11:02:14 PM, you wrote: > Nathan, > Thanks a bunch. That was exactly what I was looking for. Is there > any place you would consider a good resource to learn/get documentation > for these functions? > Matthew C. Rice > Nathan Nobbe wrote: >> On Fri, Feb 20, 2009 at 12:31 PM, Matthew C. Rice wrote: >> >>> Hello everyone, >>> >>> >>> I am building a custom PHP Extension. It is object based, and while the >>> documentation seems to be lacking a little on this aspect in extensions, I >>> haven't let that slow me down. I have used other extensions as examples, and >>> done a great deal of searching around to find everything I have needed until >>> now. >>> >>> I currently have the following http://pastebin.com/m74c98b43 ( the >>> start method ) in my classes __construct ( I actually use PHP_MALIAS to >>> alias __construct to the function ) .. This works perfect. It creates a >>> array in the object, just as I expect it to. >>> >>> I can even print out the number of elements and their values in the >>> debug function by passing $Obj->Property to it >>> >>> The problem I am having is that I can't seem to figure out a way to >>> append values on to the ZVal Array in another PHP_METHOD(). I have tried >>> combinations of zend_hash_find() && zend_hash_update() to no avail. Is >>> there anyone that might be able to point me in the right direction as to how >>> to do this? >> >> >> i think mainly you just need to read the zval from the instance, operate on >> it, then update the instance. heres some working code from the extension >> ive been working on, >> >> /* {{{ proto public void MacroCommand::addSubCommand(string commandClassRef) >> add a subcommand to this MacroCommand */ >> PHP_METHOD(MacroCommand, addSubCommand) >> { >> zval *this, *subCommands, *subCommand; >> char *rawSubCommand; >> int rawSubCommandLength; >> >> if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", >> &rawSubCommand, &rawSubCommandLength) == FAILURE) { >> RETURN_NULL(); >> } >> >> MAKE_STD_ZVAL(subCommand); >> ZVAL_STRINGL(subCommand, rawSubCommand, rawSubCommandLength, 1); >> >> this = getThis(); >> zend_class_entry *this_ce = zend_get_class_entry(this); >> subCommands = zend_read_property(puremvc_macrocommand_ce, this, >> "subCommands", >> sizeof("subCommands")-1, 1 TSRMLS_CC); >> >> ZVAL_ADDREF(subCommand); >> add_next_index_zval(subCommands, subCommand); >> >> zend_update_property(puremvc_macrocommand_ce, this, "subCommands", >> sizeof("subCommands")-1, >> subCommands TSRMLS_CC); >> } >> /* }}} */ >> >> and heres my unit test for this method, >> >> --TEST-- >> MacroCommand::addSubCommand(), ensure addSubCommand actually stores the >> ICommand in an internal array >> --SKIPIF-- >> >> --FILE-- >> > class SubCommand {} >> class MyMacroCommand extends MacroCommand { >> protected function initializeMacroCommand() { >> $this->addSubCommand('SubCommand'); >> } >> } >> $macroCmd = new MyMacroCommand(); >> var_dump($macroCmd); >> ?> >> --EXPECT-- >> object(MyMacroCommand)#1 (2) { >> ["facade:protected"]=> >> string(0) "" >> ["subCommands:private"]=> >> array(1) { >> [0]=> >> string(10) "SubCommand" >> } >> } >> >> hope this helps, >> >> -nathan >> Best regards, Marcus