src/IPAddress.php
private static function myParse(string $ipAddress, ?array &$octets = null, ?string &$error = null): bool
    {
        if ($ipAddress === '') {
            $error = 'IP address "' . $ipAddress . '" is empty.';

            return false;
        }

        $ipAddressParts = explode('.', $ipAddress);

        if (count($ipAddressParts) !== 4) {
            $error = 'IP address "' . $ipAddress . '" is invalid: IP address must consist of four octets.';

            return false;
        }

        // Validate the parts.
        $octets = [];
        foreach ($ipAddressParts as $ipAddressPart) {
            if (!self::myValidateIpAddressPart($ipAddressPart, $octet, $error)) {
                $error = 'IP address "' . $ipAddress . '" is invalid: ' . $error;

                return false;
            }

            // Save the resulting octet.
            $octets[] = $octet;
        }

        return true;
    }
private static function myParse(string $ipAddress, ?array &$octets = null, ?string &$error = null): bool
    {
        if ($ipAddress === '') {
            $error = 'IP address "' . $ipAddress . '" is empty.';

            return false;
        }

        $ipAddressParts = explode('.', $ipAddress);

        if (count($ipAddressParts) !== 4) {
            $error = 'IP address "' . $ipAddress . '" is invalid: IP address must consist of four octets.';

            return false;
        }

        // Validate the parts.
        $octets = [];
        foreach ($ipAddressParts as $ipAddressPart) {
            if (!self::myValidateIpAddressPart($ipAddressPart, $octet, $error)) {
                $error = 'IP address "' . $ipAddress . '" is invalid: ' . $error;

                return false;
            }

            // Save the resulting octet.
            $octets[] = $octet;
        }

        return true;
    }
private static function myParse ( string $ ipAddress , ? array & $ octets = null , ? string & $ error = null ) : bool { if ( $ ipAddress === '' ) { $ error = 'IP address "' . $ ipAddress . '" is empty.' ; return false ; } $ ipAddressParts = explode ( '.' , $ ipAddress ) ; if ( count ( $ ipAddressParts ) !== 4 ) { $ error = 'IP address "' . $ ipAddress . '" is invalid: IP address must consist of four octets.' ; return false ; } // Validate the parts. $ octets = [ ] ; foreach ( $ ipAddressParts as $ ipAddressPart ) { if ( ! self :: myValidateIpAddressPart ( $ ipAddressPart , $ octet , $ error ) ) { $ error = 'IP address "' . $ ipAddress . '" is invalid: ' . $ error ; return false ; } // Save the resulting octet. $ octets [ ] = $ octet ; } return true ; }
Tries to parse an IP address and returns the result or error text.

@param string      $ipAddress The IP address.
@param int[]|null  $octets    The octets if parsing was successful, undefined otherwise.
@param string|null $error     The error text if parsing was not successful, undefined otherwise.

@return bool True if parsing was successful, false otherwise.
Tries to parse an IP address and returns the result or error text .