Struct PHPVersion

Source
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

Source

pub const PHP70: PHPVersion

The PHP 7.0 version.

Source

pub const PHP71: PHPVersion

The PHP 7.1 version.

Source

pub const PHP72: PHPVersion

The PHP 7.2 version.

Source

pub const PHP73: PHPVersion

The PHP 7.3 version.

Source

pub const PHP74: PHPVersion

The PHP 7.4 version.

Source

pub const PHP80: PHPVersion

The PHP 8.0 version.

Source

pub const PHP81: PHPVersion

The PHP 8.1 version.

Source

pub const PHP82: PHPVersion

The PHP 8.2 version.

Source

pub const PHP83: PHPVersion

The PHP 8.3 version.

Source

pub const PHP84: PHPVersion

The PHP 8.4 version.

Source

pub const PHP85: PHPVersion

The PHP 8.5 version.

Source

pub const LATEST: PHPVersion = PHPVersion::PHP84

Represents the latest stable PHP version actively supported or targeted by this crate.

Warning: The specific PHP version this constant points to (e.g., PHPVersion::PHP84) is subject to change frequently, potentially even in minor or patch releases of this crate, as new PHP versions are released and our support baseline updates.

Do NOT rely on this constant having a fixed value across different crate versions. It is intended for features that should target “the most current PHP we know of now.”

Source

pub const NEXT: PHPVersion = PHPVersion::PHP85

Represents an upcoming, future, or “next” PHP version that this crate is anticipating or for which experimental support might be in development.

Warning: The specific PHP version this constant points to (e.g., PHPVersion::PHP85) is highly volatile and WILL CHANGE frequently, potentially even in minor or patch releases of this crate, reflecting shifts in PHP’s release cycle or our development focus.

Do NOT rely on this constant having a fixed value across different crate versions. Use with caution, primarily for internal or forward-looking features.

Source

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);
Source

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");
Source

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);
Source

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);
Source

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);
Source

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));
Source

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));
Source

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+
Source

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

Source§

fn clone(&self) -> PHPVersion

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PHPVersion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PHPVersion

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for PHPVersion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for PHPVersion

Source§

type Err = ParsingError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Ord for PHPVersion

Source§

fn cmp(&self, other: &PHPVersion) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for PHPVersion

Source§

fn eq(&self, other: &PHPVersion) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PHPVersion

Source§

fn partial_cmp(&self, other: &PHPVersion) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for PHPVersion

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for PHPVersion

Source§

impl Eq for PHPVersion

Source§

impl StructuralPartialEq for PHPVersion

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,