With PHP 5.3.2, bogus strings like 'http:///' throw an E_WARNING exception from parse_url() - this was fixed in 5.3.3. For the sake of those working in environments with older versions of PHP, suppressing the warnings would be helpful.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Garrett Albright’s picture

Despite the thrown warning, does the function behave correctly otherwise (returning FALSE with an illegit string)? I don't have easy access to 5.3.2 to test with.

mikeryan’s picture

Sorry for the slow response - yes, it does return FALSE, and things proceed cleanly from that point.

Thanks.

Garrett Albright’s picture

Thank you. I think I'd rather implement a wrapper around parse_url() which uses try/catch instead of using the hacky @ operator, as your patch does. But that should be an easy fix. Fortunately, it appears that D8 will require at least PHP 5.3.5, so I'll only need to implement this workaround in the D7 branch.

Garrett Albright’s picture

Issue summary: View changes
Status: Needs review » Needs work
Garrett Albright’s picture

Status: Needs work » Needs review

I'd rather implement a wrapper around parse_url() which uses try/catch instead of using the hacky @ operator

Derp, that won't work - a warning is not an exception, and can't be "caught" that way.

Okay, I made a commit that uses @ before all parse_url() calls (along with a comment stating I do not wish to be judged by it :P ). Could you have a look when the next development release is available and let me know if it works for you?

treksler’s picture

I am judging you by it :P
If anything, suppress errors on less than 5.3.3 explicitly via a small utility function

eg.

/**
 * Custom parse URL function which suppresses warnings on PHP less 
 * than 5.3.3
 * See https://drupal.org/node/2104849
 */
function pathologic_parse_url($url, $component = NULL) {
  // surpress all errors to hide warnings :(
  if (version_compare(PHP_VERSION, '5.3.3') < 0) {
    return @parse_url($url, $component);
  }
  return parse_url($url, $component);
}
Garrett Albright’s picture

Status: Needs review » Fixed

I'm pretty far from convinced that that method is better than what we've got now…

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.