Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51689 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1667 invoked from network); 14 Mar 2011 22:24:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Mar 2011 22:24:13 -0000 Authentication-Results: pb1.pair.com header.from=proofek@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=proofek@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: proofek@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:34418] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/30-33873-B859E7D4 for ; Mon, 14 Mar 2011 17:24:12 -0500 Received: by qwi4 with SMTP id 4so1671829qwi.29 for ; Mon, 14 Mar 2011 15:24:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Lp295qz0fYUhDd4f1ibSOlNxqiDpZ/Ify+eZt4wMARo=; b=mHWW4Xqb0T2nacau5mmr3HgO5QCVBjeMnkXZXtd+tTLmyR4xweZgfnxPjAB6p7uplW o9I7EZDCE4RNXQXgxaDTw/S30wvOKBCq64RHq347yGsdyLgEJmjhdnTce/PFhlEHHlI2 0HXbPeJ2DrCs7qtZuKxFhkRx9c5PwApCRGNaA= 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=o1YkGZlpxApRKL8PFrbsP7QnoCr2EyXvbB3eC75bWyJAhG886EY0QAwyUn1q5V57qC S21TkeCwOyNfKkfSlmX7wETLytQyLDQbKAlse5xIFJmOuNzdQfwbTJQvtxYCaXjzZfiD 6MiJ62/r2Vs/5+qQBD/3ctyvF9z1d84E2M6EU= MIME-Version: 1.0 Received: by 10.229.78.221 with SMTP id m29mr10609891qck.19.1300141449443; Mon, 14 Mar 2011 15:24:09 -0700 (PDT) Received: by 10.229.239.203 with HTTP; Mon, 14 Mar 2011 15:24:09 -0700 (PDT) In-Reply-To: <20110313213928.GD4446@crousti> References: <20110313213928.GD4446@crousti> Date: Mon, 14 Mar 2011 22:24:09 +0000 Message-ID: To: Etienne Kneuss Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=00235429d2bc407b50049e78c509 Subject: Re: [PHP-DEV] SplFileObject Countable From: proofek@gmail.com (Sebastian Marek) --00235429d2bc407b50049e78c509 Content-Type: text/plain; charset=UTF-8 Hello, That makes perfect sense. I have raised a feature request and have attached a patch containing both countLines() method implementation and phpt tests. thx On Sun, Mar 13, 2011 at 9:39 PM, Etienne Kneuss wrote: > On Mar 11 23:22:04, Sebastian Marek wrote: > > Hi, > > > > I have recently used SplFileObject to work with files. I was lacking a > bit > > of functionality in there regarding counting number of lines in a given > > file. Although I could just load contents of the file to an array and > check > > it size, I thought it would be nice to have SplFileObject Countable. > > > > Here is an example implementation I made tonight that seems to work well > - > > https://gist.github.com/866767 . Is it something you think would be > worth > > adding to the existing SplFileObject? Is the implementation any good? I > > reused some of the existing logic to avoid breaking > 'spl_filesystem_object' > > internal integrity, but maybe it would make sense to make it work with > the > > stream itself. > > In my oppinion, it does not make sense to implement countable for this > use. Countable should be implemented on classes where calling count() on > them is not ambiguous, i.e. the size of a collection. > > There is no reason why count() on a file should be the number of lines, > why not words, or bytes? > > I'd however be happy with a new countLines() method. > > Best, > > > > > If it's fine I can write some unit tests to cover this and then submit a > > complete patch. > > > > Regards > > -- > > Sebastian Marek > > proofek@gmail.com > > > > Follow me online at: > > Blog: http://criticallog.thornet.net/ > > Twitter: http://twitter.com/proofek > > Linkedin: http://uk.linkedin.com/in/sebastianmarek > > Ohloh: http://www.ohloh.net/accounts/proofek > > > -- Sebastian Marek proofek@gmail.com Follow me online at: Blog: http://criticallog.thornet.net/ Twitter: http://twitter.com/proofek Linkedin: http://uk.linkedin.com/in/sebastianmarek Ohloh: http://www.ohloh.net/accounts/proofek --00235429d2bc407b50049e78c509--