From dd10e70d0c46e006be47d77b793a95729d2bb675 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 29 Aug 2019 01:30:13 +0200 Subject: [PATCH] Promote Directory handler warning to error --- ext/standard/dir.c | 10 +++--- .../directory/DirectoryClass_basic_001.phpt | 11 ++++--- .../DirectoryClass_error_001-mb.phpt | 32 +++++++++++------- .../directory/DirectoryClass_error_001.phpt | 33 +++++++++++-------- 4 files changed, 52 insertions(+), 34 deletions(-) diff --git a/ext/standard/dir.c b/ext/standard/dir.c index f54fe69e25..207b02f5db 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -68,21 +68,21 @@ static zend_class_entry *dir_class_entry_ptr; myself = getThis(); \ if (myself) { \ if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \ - php_error_docref(NULL, E_WARNING, "Unable to find my handle property"); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Unable to find my handle property"); \ + return; \ } \ if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \ - RETURN_FALSE; \ + return; \ } \ } else { \ if (!DIRG(default_dir) || \ (dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \ - RETURN_FALSE; \ + return; \ } \ } \ } else { \ if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \ - RETURN_FALSE; \ + return; \ } \ } diff --git a/ext/standard/tests/directory/DirectoryClass_basic_001.phpt b/ext/standard/tests/directory/DirectoryClass_basic_001.phpt index 73aac5b43c..5594207812 100644 --- a/ext/standard/tests/directory/DirectoryClass_basic_001.phpt +++ b/ext/standard/tests/directory/DirectoryClass_basic_001.phpt @@ -15,7 +15,12 @@ echo $rc; echo "Cannot instantiate a valid Directory directly:\n"; $d = new Directory(getcwd()); var_dump($d); -var_dump($d->read()); + +try { + var_dump($d->read()); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} ?> --EXPECTF-- @@ -60,6 +65,4 @@ Class [ class Directory ] { Cannot instantiate a valid Directory directly: object(Directory)#%d (0) { } - -Warning: Directory::read(): Unable to find my handle property in %s on line 15 -bool(false) +Unable to find my handle property diff --git a/ext/standard/tests/directory/DirectoryClass_error_001-mb.phpt b/ext/standard/tests/directory/DirectoryClass_error_001-mb.phpt index d4d3eb9295..2949bd3381 100644 --- a/ext/standard/tests/directory/DirectoryClass_error_001-mb.phpt +++ b/ext/standard/tests/directory/DirectoryClass_error_001-mb.phpt @@ -29,9 +29,22 @@ try { echo "\n--> Try all methods with no handle:\n"; $d = new Directory($d); unset($d->handle); -var_dump($d->read()); -var_dump($d->rewind()); -var_dump($d->close()); + +try { + var_dump($d->read()); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($d->rewind()); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($d->close()); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} ?> --CLEAN-- @@ -40,19 +53,14 @@ $d = getcwd().PATH_SEPARATOR."私はガラスを食べられます"; rmdir($d); ?> ---EXPECTF-- +--EXPECT-- --> Try all methods with bad handle: Directory::read(): supplied argument is not a valid Directory resource Directory::rewind(): supplied argument is not a valid Directory resource Directory::close(): supplied argument is not a valid Directory resource --> Try all methods with no handle: +Unable to find my handle property +Unable to find my handle property +Unable to find my handle property -Warning: Directory::read(): Unable to find my handle property in %s on line %d -bool(false) - -Warning: Directory::rewind(): Unable to find my handle property in %s on line %d -bool(false) - -Warning: Directory::close(): Unable to find my handle property in %s on line %d -bool(false) diff --git a/ext/standard/tests/directory/DirectoryClass_error_001.phpt b/ext/standard/tests/directory/DirectoryClass_error_001.phpt index 3ff3370e4b..1a8bbf3c1d 100644 --- a/ext/standard/tests/directory/DirectoryClass_error_001.phpt +++ b/ext/standard/tests/directory/DirectoryClass_error_001.phpt @@ -25,24 +25,31 @@ try { echo "\n--> Try all methods with no handle:\n"; $d = new Directory(getcwd()); unset($d->handle); -var_dump($d->read()); -var_dump($d->rewind()); -var_dump($d->close()); + +try { + var_dump($d->read()); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($d->rewind()); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($d->close()); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} ?> ---EXPECTF-- +--EXPECT-- --> Try all methods with bad handle: Directory::read(): supplied argument is not a valid Directory resource Directory::rewind(): supplied argument is not a valid Directory resource Directory::close(): supplied argument is not a valid Directory resource --> Try all methods with no handle: - -Warning: Directory::read(): Unable to find my handle property in %s on line %d -bool(false) - -Warning: Directory::rewind(): Unable to find my handle property in %s on line %d -bool(false) - -Warning: Directory::close(): Unable to find my handle property in %s on line %d -bool(false) +Unable to find my handle property +Unable to find my handle property +Unable to find my handle property -- 2.40.0