pub struct PHPVersion(/* private fields */);Expand description
Represents a PHP version in (major, minor, patch) format,
packed internally into a single u32 for easy comparison.
§Examples
use mago_php_version::PHPVersion;
let version = PHPVersion::new(8, 4, 0);
assert_eq!(version.major(), 8);
assert_eq!(version.minor(), 4);
assert_eq!(version.patch(), 0);
assert_eq!(version.to_version_id(), 0x08_04_00);
assert_eq!(version.to_string(), "8.4.0");Implementations§
Source§impl PHPVersion
impl PHPVersion
Sourcepub const PHP70: PHPVersion
pub const PHP70: PHPVersion
The PHP 7.0 version.
Sourcepub const PHP71: PHPVersion
pub const PHP71: PHPVersion
The PHP 7.1 version.
Sourcepub const PHP72: PHPVersion
pub const PHP72: PHPVersion
The PHP 7.2 version.
Sourcepub const PHP73: PHPVersion
pub const PHP73: PHPVersion
The PHP 7.3 version.
Sourcepub const PHP74: PHPVersion
pub const PHP74: PHPVersion
The PHP 7.4 version.
Sourcepub const PHP80: PHPVersion
pub const PHP80: PHPVersion
The PHP 8.0 version.
Sourcepub const PHP81: PHPVersion
pub const PHP81: PHPVersion
The PHP 8.1 version.
Sourcepub const PHP82: PHPVersion
pub const PHP82: PHPVersion
The PHP 8.2 version.
Sourcepub const PHP83: PHPVersion
pub const PHP83: PHPVersion
The PHP 8.3 version.
Sourcepub const PHP84: PHPVersion
pub const PHP84: PHPVersion
The PHP 8.4 version.
Sourcepub const fn new(major: u32, minor: u32, patch: u32) -> Self
pub const fn new(major: u32, minor: u32, patch: u32) -> Self
Creates a new PHPVersion from the provided major, minor, and patch values.
The internal representation packs these three components into a single u32
for efficient comparisons.
§Examples
use mago_php_version::PHPVersion;
let version = PHPVersion::new(8, 1, 3);
assert_eq!(version.major(), 8);
assert_eq!(version.minor(), 1);
assert_eq!(version.patch(), 3);Sourcepub const fn from_version_id(version_id: u32) -> Self
pub const fn from_version_id(version_id: u32) -> Self
Creates a PHPVersion directly from a raw version ID (e.g. 80400 for 8.4.0).
This can be useful if you already have the numeric form. The higher bits represent the major version, the next bits represent minor, and the lowest bits represent patch.
§Examples
use mago_php_version::PHPVersion;
// "8.4.0" => 0x080400 in hex, which is 525312 in decimal
let version = PHPVersion::from_version_id(0x080400);
assert_eq!(version.to_string(), "8.4.0");Sourcepub const fn major(&self) -> u32
pub const fn major(&self) -> u32
Returns the major component of the PHP version.
§Examples
use mago_php_version::PHPVersion;
let version = PHPVersion::new(8, 2, 0);
assert_eq!(version.major(), 8);Sourcepub const fn minor(&self) -> u32
pub const fn minor(&self) -> u32
Returns the minor component of the PHP version.
§Examples
use mago_php_version::PHPVersion;
let version = PHPVersion::new(8, 2, 0);
assert_eq!(version.minor(), 2);Sourcepub const fn patch(&self) -> u32
pub const fn patch(&self) -> u32
Returns the patch component of the PHP version.
§Examples
use mago_php_version::PHPVersion;
let version = PHPVersion::new(8, 1, 13);
assert_eq!(version.patch(), 13);Sourcepub const fn is_at_least(&self, major: u32, minor: u32, patch: u32) -> bool
pub const fn is_at_least(&self, major: u32, minor: u32, patch: u32) -> bool
Determines if this version is at least major.minor.patch.
Returns true if self >= (major.minor.patch).
§Examples
use mago_php_version::PHPVersion;
let version = PHPVersion::new(8, 0, 0);
assert!(version.is_at_least(8, 0, 0));
assert!(version.is_at_least(7, 4, 30)); // 8.0.0 is newer than 7.4.30
assert!(!version.is_at_least(8, 1, 0));Sourcepub const fn is_supported(&self, feature: Feature) -> bool
pub const fn is_supported(&self, feature: Feature) -> bool
Checks if a given Feature is supported by this PHP version.
The logic is based on version thresholds (e.g. >= 8.0.0 or < 8.0.0).
Each Feature variant corresponds to a behavior introduced, removed, or changed
at a particular version boundary.
§Examples
use mago_php_version::PHPVersion;
use mago_php_version::feature::Feature;
let version = PHPVersion::new(7, 4, 0);
assert!(version.is_supported(Feature::NullCoalesceAssign));
assert!(!version.is_supported(Feature::NamedArguments));Sourcepub const fn is_deprecated(&self, feature: Feature) -> bool
pub const fn is_deprecated(&self, feature: Feature) -> bool
Checks if a given Feature is deprecated in this PHP version.
Returns true if the feature is considered deprecated at or above
certain version thresholds. The threshold logic is encoded within the match.
§Examples
use mago_php_version::PHPVersion;
use mago_php_version::feature::Feature;
let version = PHPVersion::new(8, 0, 0);
assert!(version.is_deprecated(Feature::RequiredParameterAfterOptional));
assert!(!version.is_deprecated(Feature::DynamicProperties)); // that is 8.2+Sourcepub const fn to_version_id(&self) -> u32
pub const fn to_version_id(&self) -> u32
Converts this PHPVersion into a raw version ID (e.g. 80400 for 8.4.0).
This is the inverse of [from_version_id].
§Examples
use mago_php_version::PHPVersion;
let version = PHPVersion::new(8, 4, 0);
assert_eq!(version.to_version_id(), 0x080400);Trait Implementations§
Source§impl Clone for PHPVersion
impl Clone for PHPVersion
Source§fn clone(&self) -> PHPVersion
fn clone(&self) -> PHPVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more