A
A
Alexey2015-12-11 18:27:45
PHP
Alexey, 2015-12-11 18:27:45

How to create a script for several versions of php?

Hello! I have (for example) several scripts (you can say functions or parts of code), some work fine on php 5.6, others on php 5.4.
How do they support this script on different versions of php? Do they check the version and enable one feature or the other, or something else?
Let me explain: The question is rather informative than for practice (well, or maybe it will come in handy).
Well, take for example engines, the developers of which do not know on which version the script will be used.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
trevoga_su, 2015-12-11
@trevoga_su

no one makes php scripts for multiple versions. nobody needs it.
now any norm. hosting supports the latest version of the language,
I see no problem switching to such a tariff and correcting my code

I
IceJOKER, 2015-12-11
@IceJOKER

remake them to work on the latest version you're working with (of course it's better to work on the latest stable version).

K
kompi, 2015-12-11
@kompi

The easiest option is to check the PHP_VERSION_ID constant. Minimum code.
In order not to depend on the version - check for functions. It's more code.
The most orthodox is to upgrade the scripts so that everything works fine on the latest stable. The amount of code is life-pain.

A
alex1442, 2015-12-11
@alex1442

1) see version changelogs. Adapt your code for them.
2) Cover scripts with automatic tests and catch differences in results depending on the version of php
for the first use curly braces when working with curly braces {}, for unambiguous processing of variables, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question