azjezz/psl
PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.
The IP component provides an immutable, binary-backed value object for working with IPv4 and IPv6 addresses. It supports parsing, formatting, classification, comparison, and reverse DNS lookups.
Address implements Stringable, Comparable, and Equable.
@example('networking/ip-usage.php')
There are three ways to create an Address:
Address::v4() -- parse a dotted-decimal IPv4 address.Address::v6() -- parse a colon-hex IPv6 address.Address::parse() -- auto-detect the family.You can also create an address from raw binary bytes using Address::fromBytes().
@example('networking/ip-parse.php')
Address provides methods to classify addresses into well-known categories:
| Method | IPv4 Range | IPv6 Range |
|---|---|---|
isLoopback() |
127.0.0.0/8 |
::1 |
isPrivate() |
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 |
fc00::/7 |
isLinkLocal() |
169.254.0.0/16 |
fe80::/10 |
isMulticast() |
224.0.0.0/4 |
ff00::/8 |
isUnspecified() |
0.0.0.0 |
:: |
isDocumentation() |
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 |
2001:db8::/32 |
isGlobalUnicast() |
Everything else | Everything else |
@example('networking/ip-classify.php')
@example('networking/ip-format.php')
@example('networking/ip-arpa.php')
Address implements Comparable and Equable, so addresses can be compared and sorted.
@example('networking/ip-compare.php')
Address objects can be passed directly to CIDR\Block::contains():
@example('networking/ip-cidr.php')
The Family enum represents the IP address family, with values V4 (4) and V6 (16) corresponding to their byte sizes. It also supports conversion to and from IANA address family numbers (RFC 7871).
@example('networking/ip-family.php')
See src/Psl/IP/ for the full API.
How can I help you explore Laravel packages today?