๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ
ๅฐ้พ™่™พๅฐ้พ™่™พAI
๐Ÿค–

PHP

Write solid PHP avoiding type juggling traps, array quirks, and common security pitfalls.

ไธ‹่ฝฝ2.4k
ๆ˜Ÿๆ ‡4
็‰ˆๆœฌ1.0.1
ๅฎ‰ๅ…จๅˆ่ง„
ๅฎ‰ๅ…จ้€š่ฟ‡
๐Ÿ’ฌPrompt

ๆŠ€่ƒฝ่ฏดๆ˜Ž


name: PHP slug: php version: 1.0.1 description: Write solid PHP avoiding type juggling traps, array quirks, and common security pitfalls. metadata: {"clawdbot":{"emoji":"๐Ÿ˜","requires":{"bins":["php"]},"os":["linux","darwin","win32"]}}

Quick Reference

TopicFile
Loose typing, ==, ===, type juggling, strict_typestypes.md
Associative arrays, iteration, array functionsarrays.md
Traits, interfaces, visibility, late static bindingoop.md
Encoding, interpolation, heredoc, regexstrings.md
Exceptions, error handling, @ operatorerrors.md
SQL injection, XSS, CSRF, input validationsecurity.md
PHP 8+ features, attributes, named args, matchmodern.md

Critical Rules

  • == coerces types: "0" == false is true โ€” always use === for strict comparison
  • in_array($val, $arr) uses loose comparison โ€” pass true as third param for strict
  • strpos() returns 0 for match at start โ€” use === false not !strpos()
  • Never concatenate SQL โ€” use prepared statements with PDO
  • htmlspecialchars($s, ENT_QUOTES) all output โ€” prevents XSS
  • isset() returns false for null โ€” use array_key_exists() to check key exists
  • foreach ($arr as &$val) โ€” unset $val after loop or last ref persists
  • static:: late binding vs self:: early binding โ€” static respects overrides
  • @ suppresses errors โ€” avoid, makes debugging impossible
  • Catch Throwable for both Error and Exception โ€” PHP 7+
  • declare(strict_types=1) per file โ€” enables strict type checking
  • strlen() counts bytes โ€” use mb_strlen() for UTF-8 character count
  • Objects pass by reference-like handle โ€” clone explicitly with clone $obj
  • array_merge() reindexes numeric keys โ€” use + operator to preserve keys

ๅฆ‚ไฝ•ไฝฟ็”จใ€ŒPHPใ€๏ผŸ

  1. ๆ‰“ๅผ€ๅฐ้พ™่™พAI๏ผˆWeb ๆˆ– iOS App๏ผ‰
  2. ็‚นๅ‡ปไธŠๆ–นใ€Œ็ซ‹ๅณไฝฟ็”จใ€ๆŒ‰้’ฎ๏ผŒๆˆ–ๅœจๅฏน่ฏๆก†ไธญ่พ“ๅ…ฅไปปๅŠกๆ่ฟฐ
  3. ๅฐ้พ™่™พAI ไผš่‡ชๅŠจๅŒน้…ๅนถ่ฐƒ็”จใ€ŒPHPใ€ๆŠ€่ƒฝๅฎŒๆˆไปปๅŠก
  4. ็ป“ๆžœๅณๆ—ถๅ‘ˆ็Žฐ๏ผŒๆ”ฏๆŒ็ปง็ปญๅฏน่ฏไผ˜ๅŒ–

็›ธๅ…ณๆŠ€่ƒฝ