IPAddress
final class IPAddress implements Stringable
Immutable IPv4/IPv6 address with predicates for range membership and address class.
Constants
| private PrivateRanges |
|
| private LoopbackRanges |
|
| private LinkLocalRanges |
|
| private MulticastRanges |
|
| private ReservedRanges |
|
Methods
No description
Checks for any syntactically valid IPv4 or IPv6 address, including IPv4-mapped IPv6 (::ffff:1.2.3.4).
Checks for IPv4 dotted-quad form. IPv4-mapped IPv6 is not considered IPv4; see isIPv4Mapped().
Checks for IPv6 form, including IPv4-mapped (::ffff:1.2.3.4).
Detects IPv4-mapped IPv6 (::ffff:a.b.c.d). Range predicates below normalize these — ::ffff:127.0.0.1 evaluates as loopback.
Converts IPv4-mapped IPv6 to IPv4 dotted-quad form. Returns $this for non-mapped.
Tests whether this IP falls within the given CIDR block.
Checks whether the address is publicly routable (not in any private, loopback, link-local, multicast or reserved range).
Tests RFC 1918 / RFC 4193 private ranges (10/8, 172.16/12, 192.168/16, fc00::/7).
Tests loopback ranges (127.0.0.0/8, ::1/128).
Tests link-local ranges (169.254.0.0/16 incl. cloud metadata 169.254.169.254, fe80::/10).
Tests multicast ranges (224.0.0.0/4, ff00::/8).
Tests IANA-reserved ranges not covered by other predicates: documentation prefixes (192.0.2.0/24, 2001:db8::/32), CGNAT (100.64.0.0/10), benchmarking, future-use, unspecified (0.0.0.0/8, ::/128) and similar.
No description
Details
at line 36
__construct(string $address)
No description
at line 47
static IPAddress|null
tryFrom(string $address)
No description
at line 57
static bool
isValid(string $address)
Checks for any syntactically valid IPv4 or IPv6 address, including IPv4-mapped IPv6 (::ffff:1.2.3.4).
at line 66
bool
isIPv4()
Checks for IPv4 dotted-quad form. IPv4-mapped IPv6 is not considered IPv4; see isIPv4Mapped().
at line 75
bool
isIPv6()
Checks for IPv6 form, including IPv4-mapped (::ffff:1.2.3.4).
at line 85
bool
isIPv4Mapped()
Detects IPv4-mapped IPv6 (::ffff:a.b.c.d). Range predicates below normalize these — ::ffff:127.0.0.1 evaluates as loopback.
at line 96
IPAddress
toIPv4()
Converts IPv4-mapped IPv6 to IPv4 dotted-quad form. Returns $this for non-mapped.
at line 114
bool
isInRange(string $cidr)
Tests whether this IP falls within the given CIDR block.
Accepts '192.168.1.0/24' (network with prefix) or '192.168.1.1' (exact match, implicit /32 for IPv4 or /128 for IPv6). Returns false for malformed input or different IP family. IPv4-mapped IPv6 is normalized to IPv4 when the range is in IPv4 form.
at line 163
bool
isPublic()
Checks whether the address is publicly routable (not in any private, loopback, link-local, multicast or reserved range).
at line 176
bool
isPrivate()
Tests RFC 1918 / RFC 4193 private ranges (10/8, 172.16/12, 192.168/16, fc00::/7).
at line 185
bool
isLoopback()
Tests loopback ranges (127.0.0.0/8, ::1/128).
at line 194
bool
isLinkLocal()
Tests link-local ranges (169.254.0.0/16 incl. cloud metadata 169.254.169.254, fe80::/10).
at line 203
bool
isMulticast()
Tests multicast ranges (224.0.0.0/4, ff00::/8).
at line 214
bool
isReserved()
Tests IANA-reserved ranges not covered by other predicates: documentation prefixes (192.0.2.0/24, 2001:db8::/32), CGNAT (100.64.0.0/10), benchmarking, future-use, unspecified (0.0.0.0/8, ::/128) and similar.
at line 220
string
__toString()
No description