Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73015 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73019 invoked from network); 8 Mar 2014 23:33:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2014 23:33:30 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.233 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.233 imap1.ox.registrar-servers.com Received: from [198.187.29.233] ([198.187.29.233:56556] helo=imap1.ox.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 50/64-44862-7C8AB135 for ; Sat, 08 Mar 2014 18:33:28 -0500 Received: from localhost (localhost [127.0.0.1]) by oxmail.registrar-servers.com (Postfix) with ESMTP id 871B4200089; Sat, 8 Mar 2014 18:33:25 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap1.ox.registrar-servers.com Received: from oxmail.registrar-servers.com ([127.0.0.1]) by localhost (imap1.ox.registrar-servers.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 1GxzeGKG4UFR; Sat, 8 Mar 2014 18:33:25 -0500 (EST) Received: from [192.168.0.8] (unknown [90.203.28.187]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id 08557200057; Sat, 8 Mar 2014 18:33:21 -0500 (EST) Content-Type: multipart/alternative; boundary="Apple-Mail=_139199A2-6CA1-4FE3-9819-AA752215E035" Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) In-Reply-To: Date: Sat, 8 Mar 2014 23:33:18 +0000 Cc: Marco Schuster , internals Message-ID: <9ECF5398-61A3-4235-ABB5-12EB330448BD@ajf.me> References: <03CFE6C6-0742-4928-BD2B-E9C920E9246A@ajf.me> <29BDF40C-562D-4943-877B-70701335D3AA@ajf.me> To: Chris Wright X-Mailer: Apple Mail (2.1874) Subject: Re: [PHP-DEV] Idea: ifdef-like feature to ease userland BC From: ajf@ajf.me (Andrea Faulds) --Apple-Mail=_139199A2-6CA1-4FE3-9819-AA752215E035 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On 8 Mar 2014, at 23:01, Chris Wright wrote: > Imagine that some_func() is only ever used in the context of a > foreach. For BC reasons, we have to keep this API. Since 5.5, we could > use a generator (yes, we could use an iterator, I said it was > contrived :-P), but we need to provide BC with older PHP versions: >=20 > function some_func() { > $fp =3D fopen('some_file.ext'); > #if PHP_VERSION >=3D 5.5.0 > while (false !=3D=3D $line =3D fgets($fp)) { > yield $line; > } > #else > $result =3D array(); > while (false !=3D=3D $line =3D fgets($fp)) { > $result[] =3D $line; > } > return $result; > #endif > } Ah, that=92s a good example. > **However** the thought occurs that, while potentially useful, a > pre-processor of this nature could easily be done with a userland > implementation, a composer dependency and a composer > after-install/after-update script=85 Right. You could also just use include or require to load a file with a = PHP 5.6 implementation or a PHP 5.5 implementation, conditionally, = though for differences which are just a few lines, this would be = inconvenient. -- Andrea Faulds http://ajf.me/ --Apple-Mail=_139199A2-6CA1-4FE3-9819-AA752215E035--