PHP 8.5 : le retour en force du backend moderne

PHP 8.5 : le retour en force du backend moderne


Temps de lecture estimé : 4 minutes

Fatal error: Allowed memory size exhausted in script.php on line 8
Stack trace:
#0 script.php(12): process_large_data()
#1 script.php(20): handle_request()
#2 {main}
$multiHandle = curl_multi_init();

$ch1 = curl_init('https://api.example.com/users');
$ch2 = curl_init('https://api.example.com/posts');

curl_multi_add_handle($multiHandle, $ch1);
curl_multi_add_handle($multiHandle, $ch2);

// New in PHP 8.5: Get all handles
$handles = curl_multi_get_handles($multiHandle);
// Returns: [$ch1, $ch2]

// Execute and process results
$running = null;
do {
    curl_multi_exec($multiHandle, $running);
} while ($running > 0);

foreach ($handles as $handle) {
    $response = curl_multi_getcontent($handle);
    curl_multi_remove_handle($multiHandle, $handle);
}

Nouvelles API :

#[\NoDiscard("as the operation result is important")]
function performOperation(): int {
    // Perform some operation
    return 1; // 1 for success, 0 for failure
}

// Calling the function without using the return value
// Warning: The return value of function performOperation() is expected to be consumed, as the operation result is important in test.php on line 10
performOperation();

// Calling the function and using the return value
// This will not trigger a warning
$status = performOperation();