Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79106 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72864 invoked from network); 23 Nov 2014 21:49:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2014 21:49:42 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:34964] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4C/10-05261-57652745 for ; Sun, 23 Nov 2014 16:49:41 -0500 Received: by mail-wi0-f180.google.com with SMTP id n3so4006025wiv.7 for ; Sun, 23 Nov 2014 13:49:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=kBVhbwh8P50eIpcepqmE8ttzBiNDL5JFJ6Ps3oNx8Rc=; b=erfL1fm8vs/wn5yPxBvEgSBE9+9gyLocep82za7g4Q6dEjefTFVWTIaw4TinTuutRY kStZeab5Hl9az/bZpCULBApdIJA1qfGNyA8XntKO6+xJB0GI1xIrUjnBRkWB5c6JlLBQ FnZMbjMsSfZEoMwgKSvSMSouykrKRNQkmdOrgMFnGpkZbuR5RR/JK0MWx/5RbLc0+Juc ZmKaTtZR0NmC5MQnk1FcDOCqjBZf7qe6s1bCOCKb4Hleb8dBqdx/TEppAfdJXJhBpQCa epJGLpFn+n+GUWI6gPm8BxlVO8ZUrPyw+kzYGtRmZDhiYyj9NVjjvS+qq1MBUaMPrKSd oaQA== X-Received: by 10.180.74.39 with SMTP id q7mr15878278wiv.30.1416779378269; Sun, 23 Nov 2014 13:49:38 -0800 (PST) Received: from [192.168.0.3] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id fo12sm9270056wic.19.2014.11.23.13.49.37 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 13:49:37 -0800 (PST) User-Agent: K-9 Mail for Android In-Reply-To: <012701d0074c$ccfe6f40$66fb4dc0$@devtemple.com> References: <012701d0074c$ccfe6f40$66fb4dc0$@devtemple.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Sun, 23 Nov 2014 21:47:32 +0000 To: internals@lists.php.net Message-ID: <7E8EF92A-6071-4BDA-ADD5-2C2B54AA2DCB@gmail.com> Subject: Re: [PHP-DEV] enhance fget to accept a callback From: rowan.collins@gmail.com (Rowan Collins) On 23 November 2014 18:39:18 GMT, Bill Salak wrote: >Hi list, > > > >I'm considering writing an RFC to add a 3rd parameter to fgets which >accepts >a user defined function. If we had this today we wouldn't need fgetcsv >with >the added benefit of fgetcsv style support for data packaging formats >we >would otherwise create more 1 off functions for. For example, if we >decided >to support reading json from files in the same manner as our current >fgetcsv >functionality today, we would create an fgetjson function. > > > >This change unifies the way in which we support native transliteration >of >data packaging formats from files into php data structures through a >single >interface. The other major design benefit, from my point of view, is >the >unification of userland transliteration functions/libraries with the >same >modality as our native support for these types of use cases. I believe >this >will ultimately result in more intuitive userland code around this type >of >functionality. It's an interesting idea, but I can't immediately picture how it would work - what would the callback be given, and what would it return? Would it somehow be able to manipulate the number of characters read from the stream? For any variant of CSV, reading a line at a time is what you want anyway, and you can easily build an Iterator which post-processes each line as it is read, giving the memory efficiency of fgetcsv() but much more flexibility. For JSON, newlines aren't the delimiter you want, but with nested structures, I'm not sure how you'd parse a partial structure anyway. Are there JSON equivalents of SAX (event-based) parsers? Regards, -- Rowan Collins [IMSoP]