Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43130 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28775 invoked from network); 20 Feb 2009 21:42:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2009 21:42:16 -0000 Authentication-Results: pb1.pair.com header.from=quickshiftin@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=quickshiftin@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.132.246 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: quickshiftin@gmail.com X-Host-Fingerprint: 209.85.132.246 an-out-0708.google.com Received: from [209.85.132.246] ([209.85.132.246:22727] helo=an-out-0708.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/00-28577-0A32F994 for ; Fri, 20 Feb 2009 16:41:53 -0500 Received: by an-out-0708.google.com with SMTP id c2so418956anc.38 for ; Fri, 20 Feb 2009 13:41:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=GdbIcGwdQ/h95OElQ0CUV79CbAlZ7oUkPiCj7cCBEQI=; b=w0P2EH5KZrpault9Po3ndNtQrH7xHCbrapK2lZTSd76gwcQ4qbbKKKYyffT2Hl43Xx Pm+pYu3dnQjm+cPcdjrUV4HVVuvXfD+PXh4Kl4Yc03yk4vgc9Gg5MYV5wf5BkE0VsAlw +HymgN9V8qhWTnnfYuwZhM2YIq1nt6ZBH/aFU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=SezKDwzJqJyeTDCnASr7xOc1UBLgmyNfvUfEGmuZ8Cy9U/lAraTUnAlLa4IJXM/fwW /Q0aDo5/MjuCTIlxozQUbB59NWdOwUomT0xVfHeH3uYIr1bGTwXdemN1pIk1C60D1F6H kDASFYruAJ0Tn+VgfXccyehHqc+SQCmWrMlCA= MIME-Version: 1.0 Received: by 10.231.19.204 with SMTP id c12mr1517464ibb.39.1235166110033; Fri, 20 Feb 2009 13:41:50 -0800 (PST) In-Reply-To: References: Date: Fri, 20 Feb 2009 14:41:49 -0700 Message-ID: <7dd2dc0b0902201341q61230fcavfc9fdc9f42383289@mail.gmail.com> To: "Matthew C. Rice" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=00221532cf6c3a2724046360857b Subject: Re: [PHP-DEV] Adding/Updating ZVal Arrays to Object From: quickshiftin@gmail.com (Nathan Nobbe) --00221532cf6c3a2724046360857b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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-- 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 --00221532cf6c3a2724046360857b--