Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:22:35+00:00 2026-06-02T23:22:35+00:00

I have a function in one of my PHP scripts that relies on version

  • 0

I have a function in one of my PHP scripts that relies on version 5.3 to run.

I thought that if it was in a function that didn’t happen to get called when run on a server with PHP 5.2 or earlier, then it would just be ignored. However, it turns out that when that script, and the class inside it, even just gets included, then PHP bails and stops executing.

If I can avoid it, I’d like to not have to branch of different versions of my scripts dedicated to different PHP versions. Instead, it would be ideal to be able to have code that says “If PHP version 5.3, then do this, if less, then do something different.”

I’Ve looked for some kind of “version switch” in the PHP manual, but didn’t see one.

Is a switch function like I’m describing possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:22:37+00:00Added an answer on June 2, 2026 at 11:22 pm

    There are numerous ways to solve this. I prefer detecting the version and executing function.

    1. There is a function called phpversion() or constant PHP_VERSION that gives you the current php version

      Use them like

      if(phpversion() == '5.3') {
        //specific php functions
      }
      
    2. To check if the current version is newer or equal to lets say ‘5.3.2’. simply use:

      if (strnatcmp(phpversion(),'5.3.2') >= 0) {
          # equal or newer
      }
      else {
         # not 
      }
      
    3. Or, use version_compare to know

      if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
          echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
      }
      

    Or ever more user friendly version is to use function_exists()

    if (!function_exists('function_name')) {
        // the PHP version is not sufficient
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that needs to run from command line. One of
I have a PHP file with one simple echo function: echo 'アクセスは撥ねりません。'; but when
I have been tearing my hair with this one for a while. index.php: $(document).ready(function(){
I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I'm trying to get rid of floats in my functions. I have one function
I have one javascript function that used to display the menu and content in
I have one r function i want to run it automatically(scheduling) after every predefined
I have a function in Javascript that moves one div depending on the mouse
I have two PHP scripts. One acts as a backend, and contains a class
I have cron jobs setup that runs a few PHP scripts often. The issue

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.