The php Function sodium_crypto_stream_xchacha20
The php function sodium_crypto_stream_xchacha20 encrypts data with a nonce and secret key (no authentication) to create ciphertext. The ciphertext can be expanded with the sodium_crypto_stream_xchacha20_keygen() function to generate a keystream of pseudorandom bytes that can then be encrypted with the sodium_crypto_stream_xchacha20_xor() function.
It's important to understand how a function's return type can affect the behavior of your code. PHP 8.1 has a new hint called never that can be used to indicate to PHP that a function will not return a value. This can be helpful if you have a function that always throws or exits.
Another feature added in PHP 8.1 is the ability to declare intersection types. Intersection types are similar to union types in that they allow you to declare multiple classes for a single value. However, unlike union types, pure intersection types only allow values that fulfill all of the declared class types.
fsync() and fdatasync() are two new file system functions added in PHP 8.1 that work similar to fflush(), but they write the changes to physical storage. This helps to ensure that the data stored in the application's or operating systems internal buffer can be retrieved, even in the event of an application or system crash.
Lastly, PHP 8.1 adds support for a couple of new hashing algorithms: MurmurHash3 and xxHash. Both of these are faster than many of the existing hashing algorithms. They also provide impressive output randomness, dispersion, and uniqueness. These are a great addition to the PHP cryptography library.