Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51675 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14536 invoked from network); 13 Mar 2011 21:40:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Mar 2011 21:40:17 -0000 Authentication-Results: pb1.pair.com header.from=colder@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=colder@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 94.103.100.39 as permitted sender) X-PHP-List-Original-Sender: colder@php.net X-Host-Fingerprint: 94.103.100.39 mailer.immomigsa.ch Linux 2.6 Received: from [94.103.100.39] ([94.103.100.39:32994] helo=mailer.immomigsa.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/70-11364-FB93D7D4 for ; Sun, 13 Mar 2011 16:40:16 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by mailer.immomigsa.ch (Postfix) with ESMTP id 1D6FE4B60DFF; Sun, 13 Mar 2011 22:40:13 +0100 (CET) X-Virus-Scanned: amavisd-new at immomigsa.ch Received: from mailer.immomigsa.ch ([127.0.0.1]) by localhost (mailer.immomigsa.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vNTqD0xl-Xap; Sun, 13 Mar 2011 22:40:12 +0100 (CET) Received: from crousti (46-126-188-75.dynamic.hispeed.ch [46.126.188.75]) by mailer.immomigsa.ch (Postfix) with ESMTPSA id 17FC24B60DFA; Sun, 13 Mar 2011 22:40:11 +0100 (CET) Received: by crousti (sSMTP sendmail emulation); Sun, 13 Mar 2011 22:39:28 +0100 Date: Sun, 13 Mar 2011 22:39:28 +0100 To: Sebastian Marek Cc: internals@lists.php.net Message-ID: <20110313213928.GD4446@crousti> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: [PHP-DEV] SplFileObject Countable From: colder@php.net (Etienne Kneuss) 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 >