IPAddress
in package
implements
JsonSerializable, Stringable, IEquatable
Represents an IP address.
Table of Contents
Interfaces
- JsonSerializable
- Stringable
- IEquatable
- Provides an interface for determining the value-equality of two objects.
Constants
Methods
- __construct() : mixed
- __serialize() : array<string|int, mixed>
- __toString() : string
- __unserialize() : void
- equals() : bool
- Checks whether the current object is equal to another.
- getAddress() : string
- Gets safe string representation of IP address.
- getCleanAddress() : string
- Gets string representation of IP address.
- getRaw() : string
- Get raw address bytes.
- getVersion() : int
- Gets IP version this address is for.
- getWidth() : int
- Gets the width of the raw address byte data.
- isV4() : bool
- Checks whether this is an IPv4 address.
- isV6() : bool
- Checks whether this is an IPv6 address.
- jsonSerialize() : mixed
- parse() : IPAddress
- Attempts to parse a string into an IP address.
Constants
UNKNOWN
Unknown IP version.
public
int
UNKNOWN
= 0
V4
IPv4
public
int
V4
= 4
V6
IPv6
public
int
V6
= 6
Methods
__construct()
public
__construct(string $raw) : mixed
Parameters
- $raw : string
-
Raw IP address data.
__serialize()
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__toString()
public
__toString() : string
Return values
string__unserialize()
public
__unserialize(array{: string} $serialized) : void
Parameters
- $serialized : array{: string}
equals()
Checks whether the current object is equal to another.
public
equals(mixed $other) : bool
Parameters
- $other : mixed
Return values
bool —true if the objects are equals, false if not.
getAddress()
Gets safe string representation of IP address.
public
getAddress() : string
IPv6 addresses will be wrapped in square brackets. Use getCleanAddress if this is undesirable.
Return values
string —Safe string IP address.
getCleanAddress()
Gets string representation of IP address.
public
getCleanAddress() : string
Return values
string —String IP address.
getRaw()
Get raw address bytes.
public
getRaw() : string
Return values
string —Raw address bytes.
getVersion()
Gets IP version this address is for.
public
getVersion() : int
Return values
int —IP version.
getWidth()
Gets the width of the raw address byte data.
public
getWidth() : int
4 bytes for IPv4 16 bytes for IPv6
Return values
int —Raw address byte width.
isV4()
Checks whether this is an IPv4 address.
public
isV4() : bool
Return values
bool —true if IPv4.
isV6()
Checks whether this is an IPv6 address.
public
isV6() : bool
Return values
bool —true if IPv6.
jsonSerialize()
public
jsonSerialize() : mixed
Attributes
- #[Override]
parse()
Attempts to parse a string into an IP address.
public
static parse(string $string) : IPAddress
Parameters
- $string : string
-
String to parse.
Tags
Return values
IPAddress —Representation of the given string.