Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66921 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86270 invoked from network); 3 Apr 2013 17:23:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Apr 2013 17:23:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.160.41 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.160.41 mail-pb0-f41.google.com Received: from [209.85.160.41] ([209.85.160.41:55985] helo=mail-pb0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/C4-07534-8A56C515 for ; Wed, 03 Apr 2013 12:23:53 -0500 Received: by mail-pb0-f41.google.com with SMTP id mc17so972928pbc.14 for ; Wed, 03 Apr 2013 10:23:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:sender:x-originating-ip:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:x-gm-message-state; bh=dbS5eQA1F4PzeTFWBscyeREyP5QhWSPWIQ6TynA98lg=; b=agStZ1utq0Tuu3se/tmTyL5E2Xi3K9x6c0Nx4mv0gN72JQC8m0sczBLE8pSi2cbdE0 6PX82TTwj3zdNMoReq0Yl08eE6hzKpZ2DDR6K4tyV2hZQBE1+6d2QcCGkrdrPmXalP1B nllViBx+NEYMU2YNeCYbOjdE/zt7QPUZo/UuCPo7IdOEHi0IjKe1KiRtczSGIPhlzz1h tJpeKD6IGRVs/cEFTgq8TU3+2pAs11DgUQHWQ19kWc0i00dVEBxnppcOAPeN/80AJm2N CG6rUfMEp13jvpqvAgMtlGR3HY6t3y9P9uwRd76B9sNLJbha0VbGjnbij25+Eq6zquAv 1AeQ== MIME-Version: 1.0 X-Received: by 10.66.150.198 with SMTP id uk6mr4513846pab.57.1365009829791; Wed, 03 Apr 2013 10:23:49 -0700 (PDT) Sender: php@golemon.com Received: by 10.70.28.65 with HTTP; Wed, 3 Apr 2013 10:23:49 -0700 (PDT) X-Originating-IP: [98.210.180.187] In-Reply-To: References: Date: Wed, 3 Apr 2013 10:23:49 -0700 X-Google-Sender-Auth: v62IcOz6yCzXsRjX-yG6ztLq3Fc Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQlKM731kzl3E63avOJa39GJ0HbHMG+D34Fq6huHLIY0IUPB/O1CjJyc/2TsMTC7u+tNQwIT Subject: Re: [PHP-DEV] [RFC] Simplified Array API for extensions From: pollita@php.net (Sara Golemon) > 1a) The "c" modifier seems like an unnecessary microoptimization. Compilers > should be able to optimize strlen() calls on constant strings away and even > if they didn't, it wouldn't be much of a big deal. Also using the > "c"-variants on a non-literal would not throw an error and just use an > invalid length instead. > Yeah, killing this for sure. > 1b) Imho the "l_safe" case does not need its own modifier. Typically > strings in PHP are always zero-terminated (in debug mode you'll actually get > warnings if they are not). The cases where they aren't zero-terminated are > rare and in these cases one can just write those two extra lines of code to > do the right thing. > Yeah, the safe version wasn't meant to capture a common case, but it is one I've found myself running into more a little commonly. The argument that the rest of the runtime doesn't provide this affordance is a good one, but I'm still on the fence for this one. > c) I think it would be a lot more intuitive if we used the terminology of > the normal array APIs instead of the shorthands: > > php_array_fetch => php_array_fetch_assoc > php_array_fetchl => php_array_fetch_assoc_ex > php_array_fetchn => php_array_fetch_index > php_array_fetchz => php_array_fetch_zval > +1 for consistency, combined with separating out the type conversion bits the verbosity (which I was trying to avoid) is also not so bad. > 2. The php_array_fetch*_* APIs currently combined two things: a) Fetching > from the array and b) Casting it to some type. I think both should be > separate. Not only to avoid the combinatorial explosion of different > modifier+type combinations, but also because those casting methods are also > applicable to other contexts, not just arrays casts. I asked some time ago > to add functions that can directly get a long/double from a zval (though > didn't pursue this further). Your APIs add something like that, but tightly > coupled to array fetches. There would be more use for it if it were separate > :) > It's outside the scope of what I was originally trying to accomplish, but it's got utility in its own right. So I'll rewrite this entire proposal as two separate tasks: #1 - Array access APIs for fetching zval* zend_array_(fetch|exists|unset)_(assoc|assocl|index|zval)() #1a - (Optional) Array add APIs renamed for consistency and namespacing: I'm not a huge fan of this as we'd need to keep add_(assoc|(next_)?index)_{$type}(), but it's the sort of moment to embrace consistency in the hopes of deprecating the old calls when we hit 6.0 #1b - (Optional) Some kind of foreach structure which specializes zend_hash_apply for the array case: void callback(zval *key, zval *val, void *optionalArg) { /* key as a zval owned by the iterator (is_ref=0,rc=2 - force callee to copy if they want to keep it) zend_hash_key might be more "to the point", but zval is a much more familiar structure */ /* user code here, none of that ZEND_HASH_APPLY_KEEP stuff though */ } zend_array_apply(arr, callback, optionalArg); #2 Scalar zval* accessors (with implicit type conversions): zend_(bool|long|double|string)_value() zend_is_true() technically covers zend_bool_value() already, but for consistency... And yes, I think we should move em down to Zend... -Sara