Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66915 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70416 invoked from network); 3 Apr 2013 13:31:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Apr 2013 13:31:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.43 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.219.43 mail-oa0-f43.google.com Received: from [209.85.219.43] ([209.85.219.43:43625] helo=mail-oa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/D1-07534-82F2C515 for ; Wed, 03 Apr 2013 08:31:20 -0500 Received: by mail-oa0-f43.google.com with SMTP id l10so1493710oag.16 for ; Wed, 03 Apr 2013 06:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=T2hSoMte5TPooHMJnfbKR68fSSw+zMH8jgmUxMWs2T0=; b=vfisj1TeMC2nQ7Q3GY1jVwTmPxlQhcgjulQwb1QYJ7Rj4O9NiS7Hs0mZDINeGayivX Wn997dYfUv8YCSZXsM3MHRcMHSIrWSYe+TDAm91QYSOH/zMj505EEXbyeoE9/w3G34Em 8MMxz+i6UBBtxbBIsJTZTmx7SG14zvDZugl59YNFdbTKNMezir2443RJOm1KUU+Te/DV wQbVeCaKULwCDjj76wA25h1lLfYtNjxdIJw1L74VD51e1fHiVlAq/JDCL2d+5r1b8IkW /Elq7lSl+4+ys/tTY/O/1lb7cru7vV/yRtHLjAgWlNklgE7IDtfUW18YSFh5AJ1DZTun SdQw== MIME-Version: 1.0 X-Received: by 10.182.155.66 with SMTP id vu2mr1105447obb.6.1364995878262; Wed, 03 Apr 2013 06:31:18 -0700 (PDT) Received: by 10.182.49.136 with HTTP; Wed, 3 Apr 2013 06:31:18 -0700 (PDT) In-Reply-To: References: Date: Wed, 3 Apr 2013 15:31:18 +0200 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: multipart/alternative; boundary=f46d04479faf719dbe04d974ded6 Subject: Re: [PHP-DEV] [RFC] Simplified Array API for extensions From: nikita.ppv@gmail.com (Nikita Popov) --f46d04479faf719dbe04d974ded6 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Apr 3, 2013 at 4:52 AM, Sara Golemon wrote: > https://wiki.php.net/rfc/php-array-api > I like the idea behind this, though right now that API seems a bit like a combinatorial explosion of functions and I think it would be better if one could separate different parts of it. So some feedback: 1. The list of type modifiers seems excessive and the single-character shorthands are confusing (especially as this particular set doesn't seem to be employed anywhere else in our APIs). So some particular suggestions: a) 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. b) 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. 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 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 :) Thanks, Nikita --f46d04479faf719dbe04d974ded6--