phpversion

(PHP 4, PHP 5, PHP 7, PHP 8)

phpversionObtém a versão atual do PHP

Descrição

phpversion ( string $extension = ? ) : string

Retorna uma string contendo a versão atual do interpretador PHP ou extensão.

Parâmetros

extension

Um opcional nome de extensão.

Valor Retornado

Se o parâmetro opcional extension é especificado, phpversion() retorna a versão desta extensão, ou false se não há informação da versão ou a extensão não está habilitada.

Exemplos

Exemplo #1 Exemplo phpversion()

<?php
// mostra por exemplo 'Versão Atual do PHP: 4.1.1'
echo 'Versão Atual do PHP: ' phpversion();

// mostra e.g. '2.0' ou nada se a extensão não está habilitada
echo phpversion('tidy');
?>

Notas

Nota:

Esta informação está também disponível na constante pré-definida PHP_VERSION.

Veja Também

  • version_compare() - Compares two "PHP-standardized" version number strings
  • phpinfo() - Mostra muitas informações sobre o PHP
  • phpcredits() - Mostra os créditos pelo PHP
  • php_logo_guid()
  • zend_version() - Obtém a versão da Zend engine que esta sendo executada

add a note add a note

User Contributed Notes 4 notes

up
101
cHao
10 years ago
If you're trying to check whether the version of PHP you're running on is sufficient, don't screw around with `strcasecmp` etc.  PHP already has a `version_compare` function, and it's specifically made to compare PHP-style version strings.

<?php
if (version_compare(phpversion(), '5.3.10', '<')) {
   
// php version isn't high enough
}
?>
up
12
burninleo at gmx dot net
7 years ago
Note that the version string returned by phpversion() may include more information than expected: "5.5.9-1ubuntu4.17", for example.
up
19
pavankumar at tutorvista dot com
13 years ago
To know, what are the {php} extensions loaded & version of extensions :

<?php
foreach (get_loaded_extensions() as $i => $ext)
{
   echo
$ext .' => '. phpversion($ext). '<br/>';
}
?>
up
-35
php at stampy dot me
7 years ago
If you cast the output of phpversion() to a float, it will give you the major and minor version parts as a floating point number.

This will be less useful if the minor version number is 10 or above, but for lower version numbers it works nicely.

<?
$ver
= (float)phpversion();
if (
$ver > 7.0) {
   
//do something for php7.1 and above.
} elseif ($ver === 7.0) {
   
//do something for php7.0
} else {
   
//do something for php5.6 or lower.
}
?>
To Top