diff --git a/main/streams/userspace.c b/main/streams/userspace.c index e769f2cdf22fe..73319215d2800 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -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; } diff --git a/tests/output/stream_isatty_non_castable_userwrapper.phpt b/tests/output/stream_isatty_non_castable_userwrapper.phpt new file mode 100644 index 0000000000000..cc304c19251c0 --- /dev/null +++ b/tests/output/stream_isatty_non_castable_userwrapper.phpt @@ -0,0 +1,22 @@ +--TEST-- +Non castable user-space streams (stream_cast()) +--FILE-- + +--EXPECT-- +bool(false)