PHP 치트 시트
검색 및 인쇄 가능한 PHP 8.3+ 레퍼런스 — 구문, 문자열, 배열, 함수, 클래스, enum, 속성, 최신 기능. 무료.
Basics & types
10declare(strict_types=1);
Enforce strict scalar type checks
$x = 1;
Variables start with a dollar sign
const MAX = 100;
Compile-time constant
gettype($x)
Get the type of a value
(int) $x
Cast to an integer
is_int($x)
Type-check helper (is_string, ...)
int|string $x
Union type declaration
?string $x
Nullable type (string or null)
$a ?? 'default'
Null coalescing operator
$a ??= 'default'
Assign only if null
Strings
11"Hello $name"
Double quotes interpolate variables
'literal $x'
Single quotes are literal
$a . $b
Concatenate strings
strlen($s)
Byte length of a string
str_contains($s, 'a')
Check for a substring
str_starts_with($s, 'a')
Check the prefix
substr($s, 0, 3)
Extract part of a string
str_replace('a', 'b', $s)
Replace all occurrences
explode(',', $s)
Split into an array
sprintf('%05.2f', $n)
Formatted string output
trim($s)
Strip surrounding whitespace
Arrays
11$a = [1, 2, 3];
Indexed array literal
$a = ['k' => 'v'];
Associative array
array_map(fn($x) => $x * 2, $a)
Transform each element
array_filter($a, fn($x) => $x > 0)
Keep matching elements
array_reduce($a, $fn, 0)
Reduce to a single value
in_array($v, $a, true)
Strict value check
array_keys($a)
Get all keys
array_merge($a, $b)
Merge arrays
[...$a, ...$b]
Spread/merge arrays
count($a)
Number of elements
[$x, $y] = $a;
Array destructuring
Functions
9function f(int $a): int {}
Typed parameters and return
function f(int $a = 1) {}
Default parameter value
function f(int ...$nums) {}
Variadic parameters
f(...$args)
Spread arguments
f(name: 'Sam', age: 30)
Named arguments
$fn = fn($x) => $x + 1;
Arrow function (auto-captures scope)
function () use ($x) {}
Closure capturing a variable
$fn = strlen(...);
First-class callable syntax
function f(): never {}
Never returns (throws or exits)
Control flow
9if ($a) {} elseif ($b) {} else {}
Conditional branches
$a ? $b : $c
Ternary expression
$a ?: $b
Short ternary (falsy fallback)
match ($x) { 1, 2 => 'a', default => 'b' }
Strict, expression-based match
switch ($x) { case 1: break; }
Loose multi-way branch
foreach ($a as $k => $v) {}
Iterate keys and values
for ($i = 0; $i < 10; $i++) {}
Counted loop
while ($cond) {}
Loop while a condition holds
break / continue
Exit or skip a loop iteration
Classes & OOP
10class A extends B implements C {}
Inheritance and interfaces
public function __construct(private int $id) {}
Constructor property promotion
public readonly string $name;
Immutable after initialization
public function f(): static {}
Return the late-bound type
static::create()
Late static binding
$obj?->method()
Null-safe method call
abstract class A {}
Cannot be instantiated directly
trait T {} use T;
Reusable horizontal code
$obj instanceof A
Type check at runtime
A::class
Fully-qualified class name string
Enums
9enum Status { case Active; case Draft; }
Pure enumeration
enum Status: string { case A = 'a'; }
Backed enum (string/int)
Status::Active
Reference an enum case
Status::from('a')
Build from a backing value
Status::tryFrom('x')
Returns null if invalid
Status::cases()
Array of all cases
$status->value
Backing value of a case
$status->name
Name of the case
enum E { public function label() {} }
Enums can have methods
Error handling
9try {} catch (Throwable $e) {}
Catch errors and exceptions
catch (TypeError | ValueError $e)
Catch multiple types
catch (Exception)
Non-capturing catch (no variable)
finally {}
Always runs after try/catch
throw new RuntimeException('x')
Throw an exception
throw $e;
Re-throw the caught exception
$x = $v ?? throw new Error();
Throw as an expression
$e->getMessage()
Read the error message
$e->getPrevious()
Get the chained exception
Attributes & modern
9#[Attribute] class Route {}
Declare a custom attribute
#[Route('/home')]
Apply an attribute to a target
new ReflectionClass($x)
Inspect a class via reflection
$ref->getAttributes()
Read declared attributes
json_encode($data)
Serialize to JSON
json_decode($s, true)
Decode JSON to an array
array_is_list($a)
True if keys are 0..n in order
str_word_count($s)
Count words in a string
$obj::class
Class name from an instance
“:q”와 일치하는 항목이 없습니다.
PHP 치트 시트 소개
이 PHP 치트 시트는 기초와 타입, 문자열, 배열, 함수, 제어 흐름, 클래스와 OOP, enum, 오류 처리, 어트리뷰트 및 기타 최신 기능까지 최신 PHP를 검색 가능한 한 페이지로 압축했습니다. 모든 항목은 실행 가능한 스니펫과 평이한 설명으로 구성됩니다.
PHP 8.3 이상을 대상으로 하므로, enum, readonly 속성, 생성자 프로퍼티 승격, 이름 있는 인수, match 표현식, 화살표 함수, nullsafe 호출, 어트리뷰트 등 현재 PHP를 정의하는 기능들과 함께 항상 사용하는 문자열/배열 함수도 함께 찾을 수 있습니다.
페이지는 무료이며 완전히 클라이언트 사이드로 동작합니다: 입력하는 대로 검색이 항목을 필터링하고, 고정된 섹션 메뉴가 시트 안을 이동시켜 주며, 클릭 한 번으로 스니펫이 복사되고, 인쇄 버튼으로 종이 형태의 PHP 참조 자료를 만들 수 있습니다.
PHP 치트 시트 사용 방법
- 목차를 훑어보세요 — 기초 & 타입부터 enum, 오류 처리, 어트리뷰트 & 최신 기능까지.
- 검색창에 함수 이름이나 키워드를 입력해 시트 전체를 즉시 필터링하세요.
- 고정 사이드바 내비게이션을 통해 클래스 & OOP 같은 섹션으로 이동하세요.
- 스니펫이나 복사 아이콘을 클릭해 PHP 코드를 클립보드에 복사하세요.
- 전체 참조 자료를 종이로 원한다면 인쇄를 누르세요.
자주 묻는 질문
PHP 8.3 이상을 대상으로 작성되었습니다. enum, 어트리뷰트, 최신 기능 섹션에서는 고전 문법과 함께 readonly 속성, 생성자 프로퍼티 승격, match 표현식, 이름 있는 인수, nullsafe 호출도 다룹니다.
아홉 개 섹션입니다: 기초와 타입, 문자열, 배열, 함수, 제어 흐름, 클래스와 OOP, enum, 오류 처리, 어트리뷰트 및 최신 기능 — 실제 프로젝트에서 매일 사용하는 PHP 부분들입니다.
상단의 검색창을 사용하세요. 모든 섹션의 모든 항목을 실시간으로 필터링하고 일치 개수를 보여주므로, array_map 같은 검색어를 입력하면 시트가 즉시 관련 스니펫으로 좁혀집니다.
네. 코드 자체나 마우스를 올렸을 때 나타나는 복사 아이콘을 클릭하면 스니펫이 클립보드에 담기고 짧은 "복사됨!" 표시로 확인됩니다.
네, 완전 무료입니다. 브라우저에서 렌더링되며 계정이 필요 없고 원하는 만큼 인쇄할 수 있습니다.
인기 검색어
php cheat sheet
php syntax reference
php array functions
php string functions
php enums example
php 8 attributes
php oop cheat sheet
php try catch example
도움이 필요하신가요?
이 도구에서 문제를 발견하셨나요? 저희 팀에 알려주세요.