Glob::glob() should throw an exception on error #4353

merged 1 commit into from Apr 29, 2013


None yet

3 participants


this fixes #3949.

It also makes the second argument $flags optional.

Please note: This could be a BC break as Glob::glob() no longer returns false on error and instead throws a Zend\Stdlib\Exception\RuntimeException but the ZF2 doesn't check against false.

@DASPRiD DASPRiD commented on the diff Apr 29, 2013
@@ -75,7 +80,13 @@ protected static function systemGlob($pattern, $flags)
$globFlags = 0;
- return glob($pattern, $globFlags);
+ ErrorHandler::start();
+ $res = glob($pattern, $globFlags);
+ $err = ErrorHandler::stop();
+ if ($res === false) {
DASPRiD Apr 29, 2013 Member

False may actually not directly be an error. Best is to just return an array() on false if no error is thrown. Just throw an exception if there was actually an error.

marc-mabe Apr 29, 2013 Member

glob returns false in cases of an error only. empty results, unreadable folders by permission ... are resulting in an empty array. tested with PHP-5.3.10 on Ubuntu12.

@weierophinney weierophinney added a commit that referenced this pull request Apr 29, 2013
@weierophinney weierophinney Merge branch 'hotfix/4353' into develop
Close #4353
Fixes #3949
@weierophinney weierophinney merged commit ef307f3 into zendframework:develop Apr 29, 2013

1 check failed

default The Travis build failed
@weierophinney weierophinney added a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#4353 from marc-mabe/ho…

Glob::glob() should throw an exception on error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment