Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP - Lua::getVersion() Function



The PHP Lua::getVersion() function is used to find the Lua programming language version. Lua is a lightweight, high-performance programming language used in many applications. This function helps you identify the Lua version that is currently being used in your PHP code.

It will be helpful to developers who use Lua in PHP projects. This function allows you to ensure that your Lua and PHP code are compatible. This makes it easy to manage Lua versions in your project.

Syntax

Below is the syntax of the PHP Lua::getVersion() function −

public string Lua::getVersion( void )

Parameters

This function does not have any parameters.

Return Value

The getVersion() function returns the Lua::LUA_VERSION.

PHP Version

The getVersion() function is available from version 0.9.0 of the PECL lua extension onwards.

Example 1

This basic example creates a Lua instance and prints the Lua version using the PHP Lua::getVersion() function. Finding out which Lua version is being used in your PHP environment is simple with this method.

<?php
   // Create an instance of the Lua class
   $lua = new Lua();

   // Get and print the Lua version
   echo "Lua version: " . $lua->getVersion();
?>

Output

Here is the outcome of the following code −

Lua version: 5.1

Example 2

In the below PHP code we will use the getVersion() function and check if the Lua version is '5.1' and show a message accordingly. It helps to understand how to compare Lua versions within PHP.

<?php
   $lua = new Lua();
   $version = $lua->getVersion();

   // Check if the Lua version is 5.1
   if ($version == "5.1") {
      echo "You are using Lua 5.1.";
   } else {
      echo "You are using a different Lua version.";
   }
?> 

Output

This will generate the below output −

You are using Lua 5.1.

Example 3

Now in the below code, the getVersion() function is used to get the Lua version and the result is displayed with a custom message. This shows how to format the version output with additional text.

<?php
   $lua = new Lua();
   $version = $lua->getVersion();

   // Print a custom message 
   echo "The Lua scripting language version in use is: " . $version;
?> 

Output

This will create the below output −

The Lua scripting language version in use is: 5.1
php_function_reference.htm
Advertisements