0

So I'm basically trying to create a tool that used across platforms, including sometimes legacy php version.

I don't plan on supporting anything less than 5.4 so I'd like to use something like below; however, instead of the application dying, I get various syntax errors. One of the first to start alerting is using brackets to define arrays.

Is there anyway to get around this?

if (version_compare(phpversion(), '5.4', '<')) {
    die('This tool does not support anything < PHP 5.4<br>Your PHP version is: '.phpversion() );
}

$array= ['a','b','c'];   
4
  • 1
    Possible duplicate of How to get the PHP Version? Commented Jun 13, 2018 at 21:04
  • 2
    PHP checks the script syntax before running any of it. So if you use new syntax, it will never get to the version_compare(). You have to stick to old syntax. Commented Jun 13, 2018 at 21:05
  • @Seblor He already knows how to get the version, don't you see the code? Commented Jun 13, 2018 at 21:05
  • @Barmar I may have skipped it, I read the question before the edit. My bad. Commented Jun 13, 2018 at 21:06

1 Answer 1

1

The file you are doing a version_check for should simply not use any newer PHP features or include any files that do. If you want the version_check to work on PHP 4, it can only use PHP 4 features.

Sign up to request clarification or add additional context in comments.

2 Comments

It can call newer functions, it just has to limit itself to legacy syntax. The version check will work as long as the syntax is valid.
Thanks Barmar, this was is what I was afraid of. The brackets would by far be the easiest thing to address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.