Detect PHP version in Travis

travis-ci

Solution

You can either use shell conditionals to do this:

php:
    - 5.6
    - 5.5
    - 5.4
    - 5.3

script:
    - if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.6" ]]; then export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"; fi
    - phpize #and lots of other stuff here.
    - make

Or use the build matrix with explicit inclusions:

matrix:
    include:
      - php: 5.6
        env: CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"
      - php: 5.5
        env: CFLAGS=""
      - php: 5.4
        env: CFLAGS=""
      - php: 5.3
        env: CFLAGS=""

script:
    - phpize #and lots of other stuff here.
    - make

The latter is probably what you're looking for, the former is a little less verbose.

Problem

In my Travis file I have several PHP versions and a script entry like this: ``` php: - 5.6 - 5.5 - 5.4 - 5.3 script: - export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror" - phpize #and lots of other stuff here. - make ``` I want to run the `export CFLAGS` line only when the PHP version matches 5.6. I could theoretically do that with a nasty hack to detect the PHP version from the command line, but how can I do this through the Travis configuration script?

Original source