2017-05-04 19:16:29 +03:00
|
|
|
--TEST--
|
|
|
|
Test for stream zombifying.
|
|
|
|
--SKIPIF--
|
|
|
|
<?php require('skipif.inc'); ?>
|
|
|
|
--FILE--
|
|
|
|
<?php
|
2020-07-09 05:45:00 +03:00
|
|
|
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
|
|
|
|
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
|
|
|
|
// Sometimes the error messages from PHP 8.0 may be different and have to be handled differently.
|
|
|
|
function warningHandler($errno, $errstr)
|
|
|
|
{
|
|
|
|
throw new TypeError($errstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_error_handler("warningHandler", E_WARNING);
|
|
|
|
|
2017-10-05 00:22:56 +03:00
|
|
|
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
|
|
|
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
|
2017-05-04 19:16:29 +03:00
|
|
|
|
2017-10-05 00:22:56 +03:00
|
|
|
require_once("MsCommon.inc");
|
2017-05-04 19:16:29 +03:00
|
|
|
|
2017-10-05 00:22:56 +03:00
|
|
|
$conn = connect();
|
|
|
|
if (!$conn) {
|
|
|
|
fatalError("Failed to connect.");
|
2017-05-04 19:16:29 +03:00
|
|
|
}
|
|
|
|
|
2019-01-08 02:36:59 +03:00
|
|
|
$stmt = sqlsrv_query($conn, "SELECT * FROM sys.objects");
|
2017-10-05 00:22:56 +03:00
|
|
|
$metadata = sqlsrv_field_metadata($stmt);
|
|
|
|
$count = count($metadata);
|
|
|
|
sqlsrv_fetch($stmt);
|
|
|
|
$stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM("binary"));
|
|
|
|
sqlsrv_fetch($stmt);
|
2020-07-09 05:45:00 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
$name = fread($stream, 100);
|
|
|
|
} catch (TypeError $e) {
|
|
|
|
echo $e->getMessage() . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
2017-10-05 00:22:56 +03:00
|
|
|
sqlsrv_free_stmt($stmt);
|
|
|
|
sqlsrv_close($conn);
|
2017-05-04 19:16:29 +03:00
|
|
|
|
|
|
|
?>
|
2020-07-09 05:45:00 +03:00
|
|
|
--EXPECT--
|
|
|
|
fread(): supplied resource is not a valid stream resource
|