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
Returns true for any syntactically valid IPv4 or IPv6 address, including IPv4-mapped IPv6 (::ffff:1.2.3.4).
Returns true for IPv4 dotted-quad form. IPv4-mapped IPv6 returns false; see isIPv4Mapped().
Returns true for IPv6 form, including IPv4-mapped (::ffff:1.2.3.4).
Returns true for 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.
Returns true if 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 42
__construct(string $address)
No description
at line 57
static bool
isValid(string $address)
Returns true for any syntactically valid IPv4 or IPv6 address, including IPv4-mapped IPv6 (::ffff:1.2.3.4).
at line 66
static IPAddress|null
tryFrom(string $address)
Returns an instance for valid input, null otherwise.
at line 75
bool
isIPv4()
Returns true for IPv4 dotted-quad form. IPv4-mapped IPv6 returns false; see isIPv4Mapped().
at line 84
bool
isIPv6()
Returns true for IPv6 form, including IPv4-mapped (::ffff:1.2.3.4).
at line 94
bool
isIPv4Mapped()
Returns true for IPv4-mapped IPv6 (::ffff:a.b.c.d). Range predicates below normalize these — ::ffff:127.0.0.1 evaluates as loopback.
at line 105
IPAddress
toIPv4()
Converts IPv4-mapped IPv6 to IPv4 dotted-quad form. Returns $this for non-mapped.
at line 123
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 172
bool
isPublic()
Returns true if address is publicly routable (not in any private, loopback, link-local, multicast or reserved range).
at line 185
bool
isPrivate()
Tests RFC 1918 / RFC 4193 private ranges (10/8, 172.16/12, 192.168/16, fc00::/7).
at line 194
bool
isLoopback()
Tests loopback ranges (127.0.0.0/8, ::1/128).
at line 203
bool
isLinkLocal()
Tests link-local ranges (169.254.0.0/16 incl. cloud metadata 169.254.169.254, fe80::/10).
at line 212
bool
isMulticast()
Tests multicast ranges (224.0.0.0/4, ff00::/8).
at line 223
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 229
string
__toString()
No description