Skip to content

Commit 7fac5fc

Browse files
committed
Suppress unneded warnings and exceptions
1 parent 80e8f01 commit 7fac5fc

6 files changed

+29
-24
lines changed

ext/session/session.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ PHPAPI int php_session_destroy(void) /* {{{ */
160160

161161
if (PS(id) && PS(mod)->s_destroy(&PS(mod_data), PS(id)) == FAILURE) {
162162
retval = FAILURE;
163-
php_error_docref(NULL, E_WARNING, "Session object destruction failed");
163+
if (!EG(exception)) {
164+
php_error_docref(NULL, E_WARNING, "Session object destruction failed");
165+
}
164166
}
165167

166168
php_rshutdown_session_globals();
@@ -393,7 +395,9 @@ static int php_session_initialize(void) /* {{{ */
393395
/* || PS(mod_data) == NULL */ /* FIXME: open must set valid PS(mod_data) with success */
394396
) {
395397
php_session_abort();
396-
php_error_docref(NULL, E_WARNING, "Failed to initialize storage module: %s (path: %s)", PS(mod)->s_name, PS(save_path));
398+
if (!EG(exception)) {
399+
php_error_docref(NULL, E_WARNING, "Failed to initialize storage module: %s (path: %s)", PS(mod)->s_name, PS(save_path));
400+
}
397401
return FAILURE;
398402
}
399403

@@ -405,14 +409,17 @@ static int php_session_initialize(void) /* {{{ */
405409
PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
406410
if (!PS(id)) {
407411
php_session_abort();
408-
zend_throw_error(NULL, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
412+
if (!EG(exception)) {
413+
zend_throw_error(NULL, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
414+
}
409415
return FAILURE;
410416
}
411417
if (PS(use_cookies)) {
412418
PS(send_cookie) = 1;
413419
}
414420
} else if (PS(use_strict_mode) && PS(mod)->s_validate_sid &&
415-
PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE) {
421+
PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE
422+
) {
416423
if (PS(id)) {
417424
zend_string_release_ex(PS(id), 0);
418425
}
@@ -435,7 +442,9 @@ static int php_session_initialize(void) /* {{{ */
435442
if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, PS(gc_maxlifetime)) == FAILURE) {
436443
php_session_abort();
437444
/* FYI: Some broken save handlers return FAILURE for non-existent session ID, this is incorrect */
438-
php_error_docref(NULL, E_WARNING, "Failed to read session data: %s (path: %s)", PS(mod)->s_name, PS(save_path));
445+
if (!EG(exception)) {
446+
php_error_docref(NULL, E_WARNING, "Failed to read session data: %s (path: %s)", PS(mod)->s_name, PS(save_path));
447+
}
439448
return FAILURE;
440449
}
441450

@@ -2186,7 +2195,9 @@ PHP_FUNCTION(session_regenerate_id)
21862195
if (PS(mod)->s_destroy(&PS(mod_data), PS(id)) == FAILURE) {
21872196
PS(mod)->s_close(&PS(mod_data));
21882197
PS(session_status) = php_session_none;
2189-
php_error_docref(NULL, E_WARNING, "Session object destruction failed. ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2198+
if (!EG(exception)) {
2199+
php_error_docref(NULL, E_WARNING, "Session object destruction failed. ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2200+
}
21902201
RETURN_FALSE;
21912202
}
21922203
} else {
@@ -2217,14 +2228,18 @@ PHP_FUNCTION(session_regenerate_id)
22172228

22182229
if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) {
22192230
PS(session_status) = php_session_none;
2220-
zend_throw_error(NULL, "Failed to open session: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2231+
if (!EG(exception)) {
2232+
zend_throw_error(NULL, "Failed to open session: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2233+
}
22212234
RETURN_THROWS();
22222235
}
22232236

22242237
PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
22252238
if (!PS(id)) {
22262239
PS(session_status) = php_session_none;
2227-
zend_throw_error(NULL, "Failed to create new session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2240+
if (!EG(exception)) {
2241+
zend_throw_error(NULL, "Failed to create new session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2242+
}
22282243
RETURN_THROWS();
22292244
}
22302245
if (PS(use_strict_mode) && PS(mod)->s_validate_sid &&
@@ -2234,15 +2249,19 @@ PHP_FUNCTION(session_regenerate_id)
22342249
if (!PS(id)) {
22352250
PS(mod)->s_close(&PS(mod_data));
22362251
PS(session_status) = php_session_none;
2237-
zend_throw_error(NULL, "Failed to create session ID by collision: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2252+
if (!EG(exception)) {
2253+
zend_throw_error(NULL, "Failed to create session ID by collision: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2254+
}
22382255
RETURN_THROWS();
22392256
}
22402257
}
22412258
/* Read is required to make new session data at this point. */
22422259
if (PS(mod)->s_read(&PS(mod_data), PS(id), &data, PS(gc_maxlifetime)) == FAILURE) {
22432260
PS(mod)->s_close(&PS(mod_data));
22442261
PS(session_status) = php_session_none;
2245-
zend_throw_error(NULL, "Failed to create(read) session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2262+
if (!EG(exception)) {
2263+
zend_throw_error(NULL, "Failed to create(read) session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
2264+
}
22462265
RETURN_THROWS();
22472266
}
22482267
if (data) {

ext/session/tests/session_module_name_variation3.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ ob_end_flush();
3636
string(5) "files"
3737
string(4) "user"
3838

39-
Warning: session_start(): Failed to initialize storage module: user (path: ) in %s on line %d
40-
4139
Fatal error: Uncaught Exception: Stop...! in %s:%d
4240
Stack trace:
4341
#0 [internal function]: open('', 'PHPSESSID')

ext/session/tests/session_set_save_handler_class_012.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i
4343
--EXPECTF--
4444
*** Testing session_set_save_handler() : incorrect arguments for existing handler open ***
4545
Open
46-
47-
Warning: session_start(): Failed to initialize storage module: user (path: ) in %s on line %d
4846
SessionHandler::open() expects exactly 2 arguments, 0 given
4947

5048
Warning: Undefined variable $_SESSION in %s on line %d

ext/session/tests/session_set_save_handler_error3.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ ob_end_flush();
2929
--EXPECTF--
3030
*** Testing session_set_save_handler() : error functionality ***
3131

32-
Warning: session_start(): Failed to initialize storage module: user (path: ) in %s on line %d
33-
3432
Fatal error: Uncaught Exception: Do something bad..! in %s:%d
3533
Stack trace:
3634
#0 [internal function]: open('', 'PHPSESSID')

ext/session/tests/session_set_save_handler_sid_002.phpt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,5 @@ session_unset();
7878
Fatal error: Uncaught Error: Session id must be a string in %s:%d
7979
Stack trace:
8080
#0 %s(%d): session_start()
81-
#1 {main}
82-
83-
Next Error: Failed to create session ID: user (path: %s) in %s:%d
84-
Stack trace:
85-
#0 %s(%d): session_start()
8681
#1 {main}
8782
thrown in %s on line %d

ext/session/tests/session_set_save_handler_type_error.phpt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@ ob_end_flush();
4646

4747
?>
4848
--EXPECTF--
49-
Warning: session_start(): Failed to initialize storage module: user (path: ) in %s on line %d
5049
Session callback must have a return value of type bool, array returned
5150

5251
Deprecated: session_start(): Session callback must have a return value of type bool, int returned in %s on line %d
5352

5453
Warning: session_start(): Failed to read session data: user (%s) in %s on line %d
55-
56-
Warning: session_start(): Failed to read session data: user (path: ) in %s on line %d
5754
Session callback must have a return value of type bool, array returned
5855

5956
Deprecated: session_start(): Session callback must have a return value of type bool, int returned in %s on line %d

0 commit comments

Comments
 (0)