phpversion

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

phpversionÇalışan PHP'nin sürümünü döndürür

Açıklama

phpversion(string $eklenti = ?): string

Çalışan PHP'nin veya belirtilen eklentinin sürüm numarasını bir dizge olarak döndürür.

Değiştirgeler

eklenti

İsteğe bağlı bir eklenti ismi.

Dönen Değerler

İsteğe bağlı eklenti değiştirgesi belirtilmişse işlev bu eklentinin sürüm bilgisini döndürür. Eklenti ile ilgili bir sürüm bilgisi yoksa veya eklenti etkin değilse false döner.

Örnekler

Örnek 1 - phpversion() örneği

<?php
// prints e.g. 'Current PHP version: 8.0.0'
echo 'Çalışan PHP\'nin sürümü: ' phpversion();

// eklenti etkinse '2.0' gibi bir değer basar
// eklenti etkin değilse hiçbir şey basılmaz
echo phpversion('tidy');
?>

Örnek 2 - PHP_VERSION_ID örneği

<?php
// PHP_VERSION_ID, PHP 5.2.7'den beri kullanılabilmektedir.
// Kullandığınız sürüm daha düşükse taklit edin
if(!defined('PHP_VERSION_ID'))
{
    
$version explode('.',PHP_VERSION);

    
define('PHP_VERSION_ID',
        (
$version[0] * 10000 $version[1] * 100 $version[2]));
}

// PHP_VERSION_ID bir sayı olarak tanımlanır. PHP sürümü yükseldikçe
// sayı büyür. Şu ifade ile tanımlanır:
//
// $version_id = $major_version * 10000 + $minor_version * 100 + $release_version;
//
// Artık PHP sürümlerinin özellikleri için PHP_VERSION_ID'ye bakabiliriz.
// Kullandığınız PHP sürümü bir özelliği desteklemezse version_compare()
// kullanmanız gerekmez. Örneğin 5.2.7 öncesi sürümlerden birini
// kullanıyorsanız PHP_VERSION_* sabitlerini şöyle tanımlayabilirsiniz:

if(PHP_VERSION_ID 50207)
{
    
define('PHP_MAJOR_VERSION',   $version[0]);
    
define('PHP_MINOR_VERSION',   $version[1]);
    
define('PHP_RELEASE_VERSION'$version[2]);

 
// ve böyle gider, ...
}
?>

Notlar

Bilginize:

Bu bilgi ayrıca PHP_VERSION öntanımlı sabitinde de bulunur.

Ayrıca Bakınız

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