4
PHP 8.2 in 8 code blocks
source link: https://stitcher.io/blog/php-82-in-8-code-blocks
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
« back — written by Brent on October 24, 2022
PHP 8.2 in 8 code blocks
readonly class PostData
{
public function __construct(
public string $title,
public string $author,
public string $body,
public DateTimeImmutable $createdAt,
public PostState $state,
) {}
}
$rng = $is_production
? new Random\Engine\Secure()
: new Random\Engine\Mt19937(1234);
$randomizer = new Random\Randomizer($rng);
$randomizer->shuffleString('foobar');
function alwaysFalse(): false
{
return false;
}
null
, true
, and false
as standalone types
function generateSlug((HasTitle&HasId)|null $post)
{ /* … */ }
trait Foo
{
public const CONSTANT = 1;
public function bar(): int
{
return self::CONSTANT;
}
}
function connect(
string $user,
#[\SensitiveParameter] string $password
) {
// …
}
class Post {}
$post = new Post();
$post->title = 'Name';
// Deprecated: Creation of dynamic property is deprecated
enum A: string
{
case B = 'B';
const C = [self::B->value => self::B];
}
Enum properties in const expressions
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK