Skip to content

Commit 8f8f31a

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: streams: Checking if a stream is castable should not emit warnings for user defined streams
2 parents 7723718 + d68073c commit 8f8f31a

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

main/streams/userspace.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,8 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
13841384
php_stream * intstream = NULL;
13851385
int call_result;
13861386
int ret = FAILURE;
1387+
/* If we are checking if the stream can cast, no return pointer is provided, so do not emit errors */
1388+
bool report_errors = retptr;
13871389

13881390
ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1);
13891391

@@ -1400,22 +1402,28 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
14001402

14011403
do {
14021404
if (call_result == FAILURE) {
1403-
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
1404-
ZSTR_VAL(us->wrapper->ce->name));
1405+
if (report_errors) {
1406+
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
1407+
ZSTR_VAL(us->wrapper->ce->name));
1408+
}
14051409
break;
14061410
}
14071411
if (!zend_is_true(&retval)) {
14081412
break;
14091413
}
14101414
php_stream_from_zval_no_verify(intstream, &retval);
14111415
if (!intstream) {
1412-
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
1413-
ZSTR_VAL(us->wrapper->ce->name));
1416+
if (report_errors) {
1417+
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
1418+
ZSTR_VAL(us->wrapper->ce->name));
1419+
}
14141420
break;
14151421
}
14161422
if (intstream == stream) {
1417-
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
1418-
ZSTR_VAL(us->wrapper->ce->name));
1423+
if (report_errors) {
1424+
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
1425+
ZSTR_VAL(us->wrapper->ce->name));
1426+
}
14191427
intstream = NULL;
14201428
break;
14211429
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Non castable user-space streams (stream_cast())
3+
--FILE--
4+
<?php
5+
class test_wrapper {
6+
public $context;
7+
public $return_value;
8+
function stream_open($path, $mode, $openedpath) {
9+
return true;
10+
}
11+
function stream_eof() {
12+
return false;
13+
}
14+
}
15+
16+
stream_wrapper_register('test', 'test_wrapper');
17+
$fd = fopen("test://foo","r");
18+
var_dump(stream_isatty($fd));
19+
20+
?>
21+
--EXPECT--
22+
bool(false)

0 commit comments

Comments
 (0)