public function testGetVersion() { $ip4 = new IPAddress('127.0.0.1'); $this->assertSame(IPAddressVersion::IPV4(), $ip4->getVersion()); $ip6 = new IPAddress('::1'); $this->assertSame(IPAddressVersion::IPV6(), $ip6->getVersion()); }
/** * Returns the version (IPv4 or IPv6) of the ip address * * @return IPAddressVersion */ public function getVersion() { $isIPv4 = filter_var($this->toNative(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); if (false !== $isIPv4) { return IPAddressVersion::IPV4(); } return IPAddressVersion::IPV6(); }