ZF-9957: ZF 2.0: Zend\URI\URL::validate() does not strictly validate as an absolute URL


Upfront, I'm not entirely sure if this can be called a bug since the purpose of the validate() method could be very loose in scope. However, in ZF 2.0 it's being used to replace calls to ZF 1.0's Zend_Uri::check(). In ZF 1.0, the check() method validated an absolute URI/URL and failed anything that was a relative URL (path only) or invalid URL. In ZF 2.0, validate() will not fail a relative URL. The behaviour may or may not be intentional. At present, the Zend\URI\URL::validate() method does not appear to be tested in the unit tests.

In terms of its operation, Zend\URI\URL::validate() relies solely on the use of parse_url(). If the URL is parseable (not significantly malformed) then the validation check returns TRUE. If the validation should be a strict absolute URL validator, it would need to be rewritten more in form with ZF 1.0's Zend_Uri::check().

Note: At present there is currently no strict URL validation mechanism available in ZF 2.0 as a result of this change (that I know of ;)). This will necessitate custom workarounds until the functionality is once again made available. Additionally, checks replaced with the new validation() method across all ZF 2.0 components will have introduced bugs cascading from this change. In the absence of unit tests, there's no way of knowing the method's intended purpose.


This is not a bug, but the intended behavior. Possibly documentation needs to be updated (and it will).

In ZF2, Zend\Uri represents all kinds of URIs, and supports composing, parsing, validating and manipulating both absolute and relative URIs. For this reason, Uri::validate() is very basic and in fact almost always succeeds.

If you want to make sure a URI is both valid and absolute, use:

$uri->isValid() && $uri->isAbsolute()