← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

String Offset Curly Brace Syntax

PHP PHP 5.0+ Beginner
debt(d3/e3/b3/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). The detection_hints list rector, phpstan, and phpcs — all widely-used default-tier tools in PHP CI pipelines. The code_pattern notes the $str{0} curly brace usage is straightforwardly grep-able and caught automatically by these tools, placing it firmly at d3 rather than d5 (specialist) since phpcs and phpstan are standard default tooling in most PHP projects.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix (replace pattern with safer alternative)' (e3). The quick_fix and common_mistakes both confirm the fix is a mechanical replacement: $str{0} → $str[0] across the codebase. Rector's PHP80MigrationRector set automates this entirely. While it may touch multiple files, each change is a trivial one-line substitution with no logic change, making it closer to e3 than e5.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The syntax applies across web, cli, and queue-worker contexts (broad applies_to), but once identified and replaced it imposes no ongoing structural weight. Its burden is felt during the PHP 8 migration audit window only — it doesn't shape architecture or slow future work streams after remediation, keeping it at b3 rather than b5.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The misconception field confirms the trap: developers reading pre-7.4 tutorials or Stack Overflow answers believe curly brace syntax is a valid alternative, not realising it was deprecated in 7.4 and is a fatal error in PHP 8.0+. This is a well-documented gotcha that catches developers during PHP 8 upgrades, but it is not a deep behavioural contradiction — it is a removed syntax — so t5 fits rather than t7.

About DEBT scoring →

Also Known As

$str{0} curly brace string access string index curly

TL;DR

Using $str{0} to access string characters by index — deprecated since PHP 7.4 and removed in PHP 8.0; use square bracket syntax $str[0] instead.

Explanation

PHP historically allowed both $str[0] and $str{0} to access individual characters in a string by index. The curly brace syntax $str{n} was deprecated in PHP 7.4 with a deprecation notice and fully removed in PHP 8.0 — it now produces a fatal parse error. The fix is trivial: replace {} with []. PHPStan, Rector, and PHP-CS-Fixer all detect and auto-fix this. It is purely a legacy pattern with no advantage over square brackets.

Common Misconception

Curly brace string access is an alternative valid syntax — it was an alternative in PHP 5-7.3, deprecated in 7.4, and is a fatal error in PHP 8.0+.

Why It Matters

Curly brace string offset syntax ($str{0}) was deprecated in PHP 7.4 and removed in PHP 8.0, throwing a fatal error. It appeared in older tutorials and Stack Overflow answers written before bracket syntax ($str[0]) was standardised. Codebases with legacy string manipulation code are the most likely to contain it, and grep-based detection is straightforward — making it a fast win during PHP 8 migration audits.

Common Mistakes

  • $str{0} for first character — use $str[0].
  • $str{strlen($str)-1} for last character — use $str[-1] (negative indexing, PHP 7.1+) or $str[strlen($str)-1].
  • Not running a codebase-wide search before PHP 8 upgrade.
  • Rector's PHP80MigrationRector set fixes this automatically.

Code Examples

✗ Vulnerable
// Deprecated PHP 7.4, fatal in PHP 8.0+:
$first = $str{0};               // Fatal error in PHP 8
$last  = $str{strlen($str)-1};  // Fatal error in PHP 8

if ($str{0} === '/') {          // Fatal error in PHP 8
    // ...
}
✓ Fixed
// Square brackets — always correct:
$first = $str[0];
$last  = $str[-1];             // Negative indexing (PHP 7.1+)
$last  = $str[strlen($str)-1]; // Or explicit

if ($str[0] === '/') {
    // ...
}

// Auto-fix with Rector:
// vendor/bin/rector process src --config rector.php
// Uses: \Rector\Php80\Rector\Array_\StringableToStringRector

Added 16 Mar 2026
Edited 23 Mar 2026
Views 31
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 ChatGPT 3 Ahrefs 3 SEMrush 3 Scrapy 3 Perplexity 2 Google 1 Claude 1 Meta AI 1
crawler 25 crawler_json 2
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Use str_split($str) or mb_str_split($str) for character access — the $str[0] and $str{0} syntax accesses bytes not characters and is deprecated with curly braces in PHP 7.4
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
$str{0} curly brace string offset PHP 7.4+ deprecated; $str[0] on multibyte string accessing byte not character; string index access in loop for character processing
Auto-detectable: ✓ Yes rector phpstan phpcs
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Line


✓ schema.org compliant