Re: Idea: ifdef-like feature to ease userland BC
| From: | Andrea Faulds | Date: | Sat, 08 Mar 2014 23:33:18 +0000 |
| Subject: | Re: Idea: ifdef-like feature to ease userland BC | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-73015@lists.php.net to get a copy of this message | ||
On 8 Mar 2014, at 23:01, Chris Wright <daverandom@php.net> 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:
>
> function some_func() {
> $fp = fopen('some_file.ext');
> #if PHP_VERSION >= 5.5.0
> while (false !== $line = fgets($fp)) {
> yield $line;
> }
> #else
> $result = array();
> while (false !== $line = fgets($fp)) {
> $result[] = $line;
> }
> return $result;
> #endif
> }
Ah, that’s 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…
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/