mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
streams: Checking if a stream is castable should not emit warnings for user defined streams
Closes GH-10435
This commit is contained in:
parent
64ebadcac5
commit
d68073c23b
3 changed files with 37 additions and 6 deletions
1
NEWS
1
NEWS
|
@ -14,6 +14,7 @@ PHP NEWS
|
|||
that is unset in error handler). (Girgias)
|
||||
. Fixed bug GH-12102 (Incorrect compile error when using array access on TMP
|
||||
value in function call). (ilutov)
|
||||
. Fixed warning emitted when checking if a user stream is castable. (Girgias)
|
||||
|
||||
- FPM:
|
||||
. Fixed GH-12077 (PHP 8.3.0RC1 borked socket-close-on-exec.phpt).
|
||||
|
|
|
@ -1384,6 +1384,8 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
|
|||
php_stream * intstream = NULL;
|
||||
int call_result;
|
||||
int ret = FAILURE;
|
||||
/* If we are checking if the stream can cast, no return pointer is provided, so do not emit errors */
|
||||
bool report_errors = retptr;
|
||||
|
||||
ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1);
|
||||
|
||||
|
@ -1400,8 +1402,10 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
|
|||
|
||||
do {
|
||||
if (call_result == FAILURE) {
|
||||
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
|
||||
ZSTR_VAL(us->wrapper->ce->name));
|
||||
if (report_errors) {
|
||||
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
|
||||
ZSTR_VAL(us->wrapper->ce->name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!zend_is_true(&retval)) {
|
||||
|
@ -1409,13 +1413,17 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
|
|||
}
|
||||
php_stream_from_zval_no_verify(intstream, &retval);
|
||||
if (!intstream) {
|
||||
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
|
||||
ZSTR_VAL(us->wrapper->ce->name));
|
||||
if (report_errors) {
|
||||
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
|
||||
ZSTR_VAL(us->wrapper->ce->name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (intstream == stream) {
|
||||
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
|
||||
ZSTR_VAL(us->wrapper->ce->name));
|
||||
if (report_errors) {
|
||||
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
|
||||
ZSTR_VAL(us->wrapper->ce->name));
|
||||
}
|
||||
intstream = NULL;
|
||||
break;
|
||||
}
|
||||
|
|
22
tests/output/stream_isatty_non_castable_userwrapper.phpt
Normal file
22
tests/output/stream_isatty_non_castable_userwrapper.phpt
Normal file
|
@ -0,0 +1,22 @@
|
|||
--TEST--
|
||||
Non castable user-space streams (stream_cast())
|
||||
--FILE--
|
||||
<?php
|
||||
class test_wrapper {
|
||||
public $context;
|
||||
public $return_value;
|
||||
function stream_open($path, $mode, $openedpath) {
|
||||
return true;
|
||||
}
|
||||
function stream_eof() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
stream_wrapper_register('test', 'test_wrapper');
|
||||
$fd = fopen("test://foo","r");
|
||||
var_dump(stream_isatty($fd));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(false)
|
Loading…
Add table
Add a link
Reference in a new issue