On Wed, Nov 19, 2014 at 4:10 PM, Andrea Faulds <[email protected]> wrote:
>
>> On 19 Nov 2014, at 15:07, Alain Williams <[email protected]> wrote:
>>
>> It is a problem trying to maintain code for different versions of PHP,
>> especially where there are syntax differences. It would be really nice to have
>> some sort of conditional compilation as in C. Eg:
>>
>> It would be nice to be able to do something like:
>>
>> try {
>> ....
>>
>> # if PHP_VERSION_ID > 50500
>> } catch(PDOException $e) {
>> ....
>> } finally {
>> ... tidy up
>> }
>> # else
>> } catch(PDOException $e) {
>> ... tidy up not quite where I want it
>> ....
>> }
>> # endif
>>
>> OK: '#' might not be a good character since it is start of comment, but that is
>> the idea.
>
> You could actually run the C preprocessor on your PHP codebase if you wanted!
>
> But yes, I can see there might be a need for conditional compilation. To a certain extent we
> already have this, in that you can conditionally define functions and classes. Perhaps this could be
> extended? Conditionally defining methods?
>
> class FooBar {
> if (PHP_VERSION_ID < 50000) {
> public function FooBar() {
> $this->__construct();
> }
> }
>
> public function __foobar() {
>
> }
> }
> --
[Off Topic]
It's been a long time I've been thinking about having a compile-time
preprocessor integrated into our parser/compiler stack.
I would design it just to support #migration tokens, and nothing more.
This would really ease migrations, with no runtime impact at all, and
the possibility to use any syntax, knowing it will get compiled, which
is not possible nowadays.
Like the C preprocessor. And it wouldn't be that hard to add to our
codebase, as there should not be any runtime impact, just a two-pass
parser
Anyone interested can contact me :-)
[/Off Topic]
Julien.P