Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.6.0beta3

- CLI:
. Fixed bug GH-23242 (PHP development server does not support Expect
100-continue flow control). (Sjoerd Langkemper)


27 Aug 2026, PHP 8.6.0beta2

Expand Down
110 changes: 55 additions & 55 deletions UPGRADING

Large diffs are not rendered by default.

64 changes: 11 additions & 53 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,72 +747,30 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, zend

/* TODO Split this up */
/* {{{ php_mysqli_fetch_into_hash */
void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags, int into_object)
void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags)
{
MYSQL_RES *result;
zval *mysql_result;
zend_long fetchtype;
HashTable *ctor_params = NULL;
zend_class_entry *ce = NULL;

if (into_object) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|Ch", &mysql_result, mysqli_result_class_entry, &ce, &ctor_params) == FAILURE) {
if (override_flags) {
ZEND_ASSERT(override_flags >= MYSQLI_ASSOC && override_flags <= MYSQLI_BOTH);
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
if (ce == NULL) {
ce = zend_standard_class_def;
}
if (UNEXPECTED(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) {
zend_throw_error(NULL, "Class %s cannot be instantiated", ZSTR_VAL(ce->name));
fetchtype = override_flags;
} else {
fetchtype = MYSQLI_BOTH;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &fetchtype) == FAILURE) {
RETURN_THROWS();
}
fetchtype = MYSQLI_ASSOC;
} else {
if (override_flags) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
fetchtype = override_flags;
} else {
fetchtype = MYSQLI_BOTH;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &fetchtype) == FAILURE) {
RETURN_THROWS();
}
if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");
RETURN_THROWS();
}
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");
RETURN_THROWS();
}

php_mysqli_fetch_into_hash_aux(return_value, result, fetchtype);

if (into_object && Z_TYPE_P(return_value) == IS_ARRAY) {
zval dataset;

ZVAL_COPY_VALUE(&dataset, return_value);

object_init_ex(return_value, ce);
HashTable *prop_table = zend_symtable_to_proptable(Z_ARR(dataset));
zval_ptr_dtor(&dataset);
if (!ce->default_properties_count && !ce->__set) {
Z_OBJ_P(return_value)->properties = prop_table;
} else {
zend_merge_properties(return_value, prop_table);
zend_array_release(prop_table);
}

if (ce->constructor) {
zend_call_known_function(ce->constructor, Z_OBJ_P(return_value), Z_OBJCE_P(return_value),
/* retval */ NULL, /* argc */ 0, /* params */ NULL, ctor_params);
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
zend_argument_value_error(ERROR_ARG_POS(3),
"must be empty when the specified class (%s) does not have a constructor",
ZSTR_VAL(ce->name)
);
}
}
}
/* }}} */
2 changes: 1 addition & 1 deletion ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ PHP_FUNCTION(mysqli_fetch_lengths)
/* {{{ Get a result row as an enumerated array */
PHP_FUNCTION(mysqli_fetch_row)
{
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_NUM, 0);
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_NUM);
}
/* }}} */

Expand Down
51 changes: 48 additions & 3 deletions ext/mysqli/mysqli_nonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,14 @@ PHP_FUNCTION(mysqli_connect_error)
/* {{{ Fetch a result row as an associative array, a numeric array, or both */
PHP_FUNCTION(mysqli_fetch_array)
{
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */

/* {{{ Fetch a result row as an associative array */
PHP_FUNCTION(mysqli_fetch_assoc)
{
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_ASSOC, 0);
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_ASSOC);
}
/* }}} */

Expand Down Expand Up @@ -525,7 +525,52 @@ PHP_FUNCTION(mysqli_stmt_error_list)
/* {{{ Fetch a result row as an object */
PHP_FUNCTION(mysqli_fetch_object)
{
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_ASSOC, 1);
zval *mysql_result;
zend_class_entry *ce = NULL;
HashTable *ctor_params = NULL;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|Ch", &mysql_result, mysqli_result_class_entry, &ce, &ctor_params) == FAILURE) {
RETURN_THROWS();
}
if (ce == NULL) {
ce = zend_standard_class_def;
}
if (UNEXPECTED(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) {
zend_throw_error(NULL, "Class %s cannot be instantiated", ZSTR_VAL(ce->name));
RETURN_THROWS();
}
if (!ce->constructor && ctor_params && zend_hash_num_elements(ctor_params) > 0) {
zend_argument_value_error(ERROR_ARG_POS(3),
"must be empty when the specified class (%s) does not have a constructor",
ZSTR_VAL(ce->name)
);
RETURN_THROWS();
}

MYSQL_RES *result;
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

zval dataset;
php_mysqli_fetch_into_hash_aux(&dataset, result, MYSQLI_ASSOC);

if (Z_TYPE(dataset) == IS_ARRAY) {
object_init_ex(return_value, ce);
HashTable *prop_table = zend_symtable_to_proptable(Z_ARR(dataset));
zval_ptr_dtor(&dataset);
if (!ce->default_properties_count && !ce->__set) {
Z_OBJ_P(return_value)->properties = prop_table;
} else {
zend_merge_properties(return_value, prop_table);
zend_array_release(prop_table);
}

if (ce->constructor) {
zend_call_known_function(ce->constructor, Z_OBJ_P(return_value), Z_OBJCE_P(return_value),
/* retval */ NULL, /* argc */ 0, /* params */ NULL, ctor_params);
}
} else {
RETURN_COPY_VALUE(&dataset);
}
}
/* }}} */

Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/mysqli_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern void php_mysqli_dtor_p_elements(void *data);

extern void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status);

extern void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flag, int into_object);
extern void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flag);
extern void php_clear_stmt_bind(MY_STMT *stmt);
extern void php_clear_mysql(MY_MYSQL *);
extern MYSQLI_WARNING *php_get_warnings(MYSQLND_CONN_DATA * mysql);
Expand Down
26 changes: 26 additions & 0 deletions sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ typedef struct php_cli_server_client {
bool request_read;
bool too_large_post;
bool headers_written;
bool expect_continue;
zend_string *current_header_name;
zend_string *current_header_value;
enum { HEADER_NONE=0, HEADER_FIELD, HEADER_VALUE } last_header_element;
Expand Down Expand Up @@ -1794,6 +1795,13 @@ static int php_cli_server_client_read_request_on_headers_complete(php_http_parse
return 2;
}

zval *expect_val = zend_hash_str_find(&client->request.headers, "expect", sizeof("expect") - 1);
if (expect_val && Z_TYPE_P(expect_val) == IS_STRING
&& zend_string_equals_literal_ci(Z_STR_P(expect_val), "100-continue")
&& parser->http_major == 1 && parser->http_minor == 1) {
client->expect_continue = true;
}

return 0;
}

Expand Down Expand Up @@ -1901,6 +1909,23 @@ static int php_cli_server_client_read_request(php_cli_server_client *client, cha
return -1;
}

if (client->expect_continue && !client->request_read) {
/* Parser completed headers with Expect: 100-continue but hasn't
* finished reading the body. Send 100 Continue before the client
* sends the request body. Only supported in HTTP/1.1. */
static const char continue_response[] = "HTTP/1.1 100 Continue\r\n\r\n";
bool send_success = false;
client->expect_continue = false;
zend_try {
size_t sent = php_cli_server_client_send_through(client, continue_response, strlen(continue_response));
send_success = sent == strlen(continue_response);
} zend_end_try();
if (!send_success) {
*errstr = php_socket_strerror(php_socket_errno(), NULL, 0);
return -1;
}
}

return client->request_read ? 1: 0;
}
/* }}} */
Expand Down Expand Up @@ -1985,6 +2010,7 @@ static void php_cli_server_client_ctor(php_cli_server_client *client, php_cli_se
client->request_read = false;
client->too_large_post = false;
client->headers_written = false;
client->expect_continue = false;

client->last_header_element = HEADER_NONE;
client->current_header_name = NULL;
Expand Down
3 changes: 2 additions & 1 deletion sapi/cli/tests/php_cli_server.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CliServerInfo {
public function __construct(
public string $docRoot,
public $processHandle,
public $outputFile,
) {}
}

Expand Down Expand Up @@ -118,7 +119,7 @@ function php_cli_server_start(
define("PHP_CLI_SERVER_PORT", $port);
define("PHP_CLI_SERVER_ADDRESS", PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_PORT);

return new CliServerInfo($doc_root, $handle);
return new CliServerInfo($doc_root, $handle, $output_file);
}

function php_cli_server_connect() {
Expand Down
35 changes: 35 additions & 0 deletions sapi/cli/tests/php_cli_server_expect_100_continue_curl.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
Expect 100-continue behavior in PHP development server (curl)
--SKIPIF--
<?php
include "skipif.inc";
?>
--EXTENSIONS--
curl
--FILE--
<?php
include 'php_cli_server.inc';
$server = php_cli_server_start();

// Generate a POST body larger than 1MB to trigger Expect: 100-continue
$body = str_repeat('A', 1024 * 1024 + 1);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, PHP_CLI_SERVER_ADDRESS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

// Set a high timeout for 100-continue response
curl_setopt($ch, CURLOPT_EXPECT_100_TIMEOUT_MS, 2000);

curl_exec($ch);
var_dump(curl_errno($ch));

echo "Did the PHP development server send a HTTP/1.1 100 Continue header?\n";
$start_transfer_time = curl_getinfo($ch, CURLINFO_STARTTRANSFER_TIME_T);
var_dump($start_transfer_time < 1_000_000);
?>
--EXPECT--
int(0)
Did the PHP development server send a HTTP/1.1 100 Continue header?
bool(true)
33 changes: 33 additions & 0 deletions sapi/cli/tests/php_cli_server_expect_100_continue_iua.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Failure to send "100 Continue" is reported with ignore_user_abort=1
--SKIPIF--
<?php
include "skipif.inc";
if (!extension_loaded("sockets")) die("skip sockets extension required");
if (PHP_OS_FAMILY === "Windows") die("skip SO_LINGER reset behaviour differs on Windows");
?>
--FILE--
<?php
include "php_cli_server.inc";
$server = php_cli_server_start('echo "Hello world";', 'index.php', ['-d', 'ignore_user_abort=1']);

$fp = fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT);
socket_set_option(socket_import_stream($fp), SOL_SOCKET, SO_LINGER, ['l_onoff' => 1, 'l_linger' => 0]);
fwrite($fp, "POST / HTTP/1.1\r\nExpect: 100-continue\r\nContent-Length: 4\r\n\r\n");
fclose($fp);

$output = '';
for ($i = 0; $i < 100 && !str_contains($output, 'Invalid request'); $i++) {
usleep(50000);
$output = file_get_contents($server->outputFile);
}

var_dump(str_contains($output, 'Invalid request'), str_contains($output, 'Unexpected EOF'));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/php_cli_server_expect_100_continue_iua.log')
?>
--EXPECT--
bool(true)
bool(false)
Loading
Loading