Alright, so my last article about PHP 8.1 coming features was pretty well received, and I thought it was worth to go for a second round to talk about all these interesting changes, improvements and features coming to us. Let’s dive into it!
<?php
interface A {}
interface B {}
class C implements A, B {}
class D implements A {}
class Test
{
public A&B $property;
}
$test = new Test();
$test->property = new C(); // Works well!
$test->property = new D(); // Forbidden, D doesn't implement A and B
fsync
and fdatasync
Well, think of fsync
and fdatasync
as the “Eject” operation of an USB stick. These methods ensure data of your file are physically written on the storage. The difference with fflush
is this last only tells PHP to flush your data to the OS internal buffer. It doesn’t tell the OS to physically write your data to the given storage. If fsync
and fdatasync
are successful, you know your data are fully persisted, even if a power outage happens just after. Here is the difference between these two functions:
fsync
will persist data and metadata of your file. Metadata includes date of creation and update, filename, author’s name and so on ;fdatasync
will only persist data, without metadata, which can result in a slightly faster operation.#programming #releases #php