跳转到内容
代码片段·免费

PHP 代码片段

20 个 PHP 8 代码片段:严格类型、枚举、readonly 类、构造函数属性提升、match、带预处理语句的 PDO、JSON、会话、输入校验、HTML 转义和 PHPUnit 测试。部分需要 PHP 8.1 或 8.2。

免费安装。

如果你的 Android 设备上装了 PocketCode,这会在应用里打开此页面。

预览

20 个中的 5 个

Strict file headerstrict

Start a file with strict types and a namespace

<?php

declare(strict_types=1);

namespace ${1:App};

$0

Interfaceiface

Interface with one typed method

interface ${1:Repository}
{
    public function ${2:all}(): array;
}

Backed enumenumb

Enum whose cases map to strings (PHP 8.1+)

enum ${1:Status}: string
{
    case ${2:Active} = '${3:active}';
    case ${4:Inactive} = '${5:inactive}';
}

Composer autoloadautoload

Load the classes installed with Composer

require __DIR__ . '/vendor/autoload.php';

Traittraitb

Reusable methods to mix into several classes

trait ${1:HasTimestamps}
{
    $0
}

1.0.0 的变更

首个版本。

相关