TGViewer
samdark blog ☕️ (Alexander Makarov) samdark blog ☕️ (Alexander Makarov) @samdark_blog · 1.62K subscribers
Post #407 1.61K
📄 PER-CS v3.1

PHP's coding style is just about to get its new version. 3.1 fixes a few clarity and wording issues but also there are some interesting changes. You can check these yourself, there's a changelog. I'll, instead provide a few numbered code snippets to discuss.

🔸1 — clone with parenthesis

$b = clone($a);
$b = clone($a, [
'foo' => 'bar',
]);


🔸2 — switch-case-match

switch (true) {
case (
$a === 10
&& $b === 20
):
doSomething();
break;
}


🔸3 — spaces around pipe operator

$result = $input |> trim(...) |> strtoupper(...);


🔸4 — chaining

$result = '<foo>'
|> strtoupper(...)
|> htmlspecialchars(...);


🔸5 — empty closures

$noOpFunction = function () {};

// SHOULD be preferred where possible:
$noOpFunction = fn() => null;


🔸6 — anonymous classes

$example = new
#[Attribute]
class {
// ...
};


🔸7 — enums and scoping (private)

<?php

enum Size
{
case Small;
case Medium;
case Large;

private const Huge = self::Large;
}


🔸8 - arrays

return [
'foo',
'bar',
];

someFunction([
'foo',
'bar',
]);


#php #psr12 #percs
GitHub per-coding-style/migration-3.1.md at master · php-fig/per-coding-style PER coding style. Contribute to php-fig/per-coding-style development by creating an account on GitHub.
  • 👍 14
  • 🔥 11
More from @samdark_blog
  1. Sep 22, 2026⏩ Re-benchmarked different ways to serve PHP Some time ago I've made some benchmarks to fi…
  2. Sep 9, 2026Пыхник’26 — целая неделя PHP! С 28 сентября по 2 октября пройдёт Пыхник’26 — онлайн-конфер…
  3. Sep 8, 2026My name is Taras Soroka. I’m a CTO, digital transformation consultant, mentor, and the hos…
  4. Sep 8, 2026💬 Bjarne Stroustrup on AI Code will still be written by humans, and they will rely on abs…
  5. Sep 7, 2026🌬 TION MagicAir CO² sensor calibration via USB HID I have a Tion breather and a MagicAir…
  6. Sep 7, 2026🧰 Running Gitea container on older kernels I'm running Gitea at my Synology NAS which has…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →