PHP Annotated – October 2020

Php_annotated_monthly 이미지

Roman Pronskiy가 쓰고 JetBrains에서 제공하는 월간 PHP Annotated 2020년 10월호의 번역/해석본입니다.

이 중에서 몇 가지 제 취향껏 골라 그 안의 내용도 좀 뒤져보고 개발새발 번역해서 소개합니다.


⚡️ News & Releases

PHP 8.0.0 RС 2

PHP 8의 release candidate 시리즈가 시작됐습니다. 최종 릴리스 전까지 두 개의 RC가 남아 있습니다.

8.0을 위한 별도의 branch가 생성되었고, master branch는 이제 PHP 8.1을 바라보고 있습니다(php-src 저장소에는 master branch를 “Active development branch for PHP 8.1”라고 설명하고 있습니다).

PHP 8의 새로운 기능에 대한 개요는 다음 블로그 게시물에서 찾을 수 있습니다.

IDE에서 다루는 방법은 PhpStorm의 블로그 글이나 동영상으로 확인하실 수 있습니다.
Larry Garfield는 삶의 질을 높여주는 PHP 8 신규 기능에 관한 글을 쓰기도 했습니다.
PHP.Watch에선 PHP 8의 변경 사항을 한눈에 볼 수 있게 정리가 되어 있습니다.

PHP 8을 사용해보시려면, php:rc-cli를 이용하면 Docker로 가능하고, Mac에서는 shivammathur/homebrew-php, 혹은 php-build 소스로 컴파일 해보실 수 있습니다.

또한 Brent Roose와 Freek Van der Herten의 PHP 8을 사용하여 최신 애플리케이션을 구축하는 방법에 관한 eBook(발매 예정)인 Front Line PHP의 업데이트를 구독 할 수 있습니다.

PhpStorm 2020.3 EAP

https://blog.jetbrains.com/phpstorm/2020/10/phpstorm-2020-3-early-access-program-is-now-open/

PhpStorm의 EAP(early access program)을 사용하면 다음 릴리스에서 제공될 새로운 기능을 사용해 볼 수 있습니다. PHP 8 support, PHPStan, Psalm이 잘 작동하고 있고, 이외에 다른 변경 사항이 많이 있습니다. 심지어 2020.3의 두 번째 EAP 빌드에선 @template을 통해 generic을 지원하는 첫 번째 시도입니다(experimental).

PHP

PHP 7.2.34
PHP 7.3.23
PHP 7.4.11

Xdebug 3.0 beta 1

https://xdebug.org/announcements/2020-10-14

이 세 번째 버전에서는 디버거와의 작업을 더 쉽게 시작할 수 있도록 설정 방식이 재 설계되었습니다. 단 하나의 옵션 만이 필수입니다 : xdebug.mode=debug 혹은 command line에서 export XDEBUG_MODE=debug. 기본 포트는 9000에서 9003으로 변경됐고, 같은 포트를 사용하는 php-fpm과 더는 충돌하지 않습니다. upgrade guide를 확인해보세요.

Composer 2.0.0 RC2

https://getcomposer.org/changelog/2.0.0-RC2

최종 버전 전의 마지막 RC입니다. 시도해보시려면 composer self-update --preview를 실행해보세요.

🐘 PHP Internals

✅ [PR] Attributes on property groups

https://github.com/php/php-src/pull/6186

이제 Attribute를 하나 하나 지정하는 대신 property 그룹 전체에 지정할 수 있습니다. 액세스 수정자에서와 완전히 동일하게 작동합니다.

class FooBar {
#[NonNegative]
public int $x, $y, $z;
}

✅ [PR] Attributes and strict types

https://externals.io/message/111915

이제 Attribute는 strict_types=1 지시자도 고려합니다.

[PR] OPCache: Direct execution opcode file without php source code file

https://github.com/php/php-src/pull/6146

이 PR에서, 저자는 opcache 바이너리 파일을 저장하고 소스 코드 없이도 실행할 수 있게 제안합니다 - Python의 .pyc / .pyo의 파일과 유사한 방식.

그러나 이에 관한 논의에서 이 접근 방식의 몇 가지 문제점이 드러났습니다. PHP의 opcode 형식이 불안정하고, 다른 버전 간에 서로 호환되지 않습니다. 예를 들어, 패치 릴리스 사이에서도 PHP 7.4.22로 컴파일 된 코드는 PHP 7.4.23에서 segfault로 실패 할 수 있습니다.

AMA with the PhpStorm team

https://www.reddit.com/r/PHP/comments/j65968/ama_with_the_phpstorm_team_from_jetbrains_on/

최근 Reddit에서의 AMA(Ask Me Anything) with the PhpStorm team에서 Nikita는 generic의 상태와 전망에 대해 자세히 언급했습니다. 요컨대, 런타임에 삭제되는 제네릭은 순전히 기술적인 관점에서 가장 실행 가능한 접근 방식이지만 동시에 매우 일관성이없고 형식 안전성에 구멍을 남깁니다.

[PR] Multiline arrow functions

https://github.com/php/php-src/pull/6246

PHP 7.4에 추가된 arrow 함수는 한 줄짜리 표현식만 가능했습니다. 이 PR은 여러 줄의 짧은 람다식을 가능하게 합니다.

$guests = array_filter($users, fn ($user) => {
$guest = $repository->findByUserId($user->id);
return $guest !== null && in_array($guest->id, $guestsIds);
});

일반적인 람다 함수에 비해 갖는 이점은 use를 쓰지 않고도 scope를 캡쳐할 수 있다는 점입니다.

문법에 화살표(=>)를 추가할지에 대한 질문도 남겼습니다. fn() => {} vs. fn() {}

🆕 [RFC] Short Functions

https://wiki.php.net/rfc/short-functions

이 RFC는 화살표 함수 구문으로 명명된(named) 함수나 메소드에 단순 반환 표현식을 쓰도록 제안합니다.

function pick_one(int $a) => match($a) {
1 => 'One',
2 => 'Two',
3 => 'Three',
default => 'More',
};
print pick_one(1) . PHP_EOL;
class Person
{
public function __construct(
private string $firstName,
) {}
public function getFirstName(): string => $this->firstName;
}

🛠 Tools

thephpleague/event 3.0.0

https://github.com/thephpleague/event

이 유명한 이벤트 패키지는 이제 PSR-14와 호환됩니다.

terrylinooo/simple-cache

https://github.com/terrylinooo/simple-cache

PSR-16 simple cache drivers for files, Redis, MySQL, SQLite, APC, APCu, Memcache, Memcached, and WinCache

Bolt 4.0

https://github.com/bolt/core

즉시 사용 가능한 REST, GraphQL API 그리고 i18n과 함께 컴포저 패키지로 구워진 Symfony 5 CMS.

PHP-DI

https://github.com/PHP-DI/PHP-DI

실용적이고 프레임웍에 구애받지 않는 의존성 주입 컨테이너.

markrogoyski/math-php

https://github.com/markrogoyski/math-php

PHP를 위한 강력하고 현대적인 수학 라이브러리.

Danack/FloatHex

https://github.com/Danack/FloatHex

Float 형을 16 진수 문자열로 변환하고 그 반대로 되돌리는 기능과 2진 표현으로 두 개의 부동 소수점 숫자를 표시하는 등의 함수들. 또는 float_compare(0.3, 0.1 + 0.2);를 사용하면 0.1 + 0.2 === 0.3이 왜 false인지 알 수 있습니다.

float_compare 이미지

marcocesarato/PHP-Antimalware-Scanner

https://github.com/marcocesarato/PHP-Antimalware-Scanner

PHP 파일을 스캔하고 프로젝트를 분석하여 그 안에있는 악성 코드를 찾는 도구입니다.

Prometheus PHP

https://github.com/PromPHP

prometheus.io를 위한 비공식 PHP용 라이브러리.

shivammathur/setup-php

https://github.com/shivammathur/setup-php

파이프라인에서 환경을 준비하기 위해 PHP, 확장 및 기타 사항을 설정하기 위한 GitHub Action. Github 블로그에서 이에 관한 간략한 개요를 제공합니다.

Symfony

Dynamically changing the log level in Symfony apps.

https://matthiasnoback.nl/2020/09/symfony-changing-the-log-level/

A Week of Symfony #720 (12-18 October 2020)

https://symfony.com/blog/a-week-of-symfony-720-12-18-october-2020

New Symfony core team members.

https://symfony.com/blog/new-core-team-members

What’s coming in Symfony 5.2

https://symfony.com/blog/category/living-on-the-edge/5.2

다가오는 Symfony 릴리스는 무엇보다도 PHP 8과 호환됩니다. Symfony 5.2는 PHP 8 attributes 몇가지를 가져왔습니다. 예를 들어, 라우팅을 위해서는 #[Route('/path', name: 'action')], 의존성을 위해서는 #[Required], 그리고 user를 가져오기 위해 #[CurrentUser]와 같은 controller parameter를 위한 attribute를 사용할 수 있습니다.

public function index(#[CurrentUser] MyUser $user) { /* ... */ }

Laravel

ksassnowski/venture

https://github.com/ksassnowski/venture

이 패키지를 사용하면 Laravel의 Queue 시스템을 사용하여 상호 의존적인 작업의 복잡한 워크플로우를 구축할 수 있습니다.

spatie/laravel-typescript-transformer

PHP 클래스를 기반으로 TypeScript 타입을 생성하여 frontend에서 사용할 수 있게 합니다. 이 게시글로부터 이를 사용해야할 동기를 확인해보세요.

https://github.com/spatie/laravel-typescript-transformer

Spatie’s updated PHP and Laravel guidelines.

https://spatie.be/guidelines/laravel-php

Spatie의 Laravel & PHP guideline이 업데이트 됐습니다.

spatie/spatie.be

https://github.com/spatie/spatie.be

Spatie에 있는 친구들이 spatie.be 웹 사이트의 코드를 오픈 소스로 제공합니다. 또한 구현에 대한 모든 세부 사항이 포함된 자습서 시리즈를 출시했습니다.

The complete guide to Laravel frontend scaffolding.

https://samuelstancl.me/blog/the-complete-guide-to-laravel-frontend-scaffolding//

📺 Laravel Worldwide Meetup #3:

Exploring The Magic Of PhpStorm – Adel Faizrakhmanov
I’d Like To Speak To Your Manager – Yaz Jallad.

📺 Stream: Generate dynamic open graph images for freek.dev blog posts.

https://www.youtube.com/watch?v=sHS2gVFaTjo

📺 Taylor answers questions regarding Jetstream.

https://www.youtube.com/watch?v=krn39HjxPTs

Yii

W3C will move on from WordPress and will instead use CraftCMS

W3C가 WordPress 대신 Yii 2를 기반으로하는 CraftCMS로 옮겨가기로 했습니다. 이 결정을 하게 된 이유를 설명하는 이 문서가 아니었다면, 이 뉴스 자체는 그다지 흥미롭진 않았을 겁니다.

🌀 Async PHP

micc83/mailamie

https://github.com/micc83/mailamie

테스트를 위해 SMTP를 포괄하는 서버. ReactPHP를 기반으로 만들어졌습니다.

clue/reactphp-mq

https://github.com/clue/reactphp-mq

가벼운 인메모리 메세지 큐.

💡 기타 읽을 만한 글

Transpiling PHP code from 8.0 to 7.x via Rector

https://blog.logrocket.com/transpiling-php-code-from-8-0-to-7-x-via-rector/

최신 버전의 PHP로 업그레이드 할 수 없지만 개발할 때는 새로운 기능을 사용하려면, 프로젝트에 “컴파일”단계를 추가하고 rector/rectorphp의 도움으로 캐발 코드를 다운그레이드 할 수 있습니다.

Error suppression operator @ usage analysis.

https://www.exakat.io/en/i-scream-you-scream-we-all-scream-for/

에러를 무시하는 @ 연산자가 사용되는 경우와 대안, @와 함께 가장 많이 사용되는 함수 등을 정리했습니다.

PHP 8.0 named parameters and variadic

https://www.exakat.io/en/php-8-0-named-parameters-and-variadic/

임의의 개수의 인수로 함수를 호출하고 스프레드 오퍼레이터(Spread Operator, 펼침/전개 연산자)를 사용하는 방법에 대해 설명합니다.

.gitattributes for PHP projects.

https://php.watch/articles/composer-gitattributes

Instructions on how to write tests for PHP itself

https://dev.to/realflowcontrol/growing-the-php-core-one-test-at-a-time-4g4k

PHP 자체를 위한 테스트 작성하기. 테스트는 PHP로 작성되었으므로 이를 위해 C를 알아야 할 필요는 없습니다.

Set up PhpStorm to use PHP with PHPUnit and Xdebug in Docker.

https://pen-y-fan.github.io/2020/10/10/Set-up-PhpStorm-to-use-PHP-with-PHPUnit-and-xDebug-in-Docker/

Caching makes everything faster. Right?

https://thephp.cc/news/2020/10/caching-makes-everything-faster-right

PHPUnit에서 코드 커버리지를 위한 캐싱을 추가한 것이 원하는 효과를 얻지 못한 이유와 이 문제가 마침내 어떻게 해결 되었는지에 대한 PHPUnit 작성자인 Sebastian Bergmann의 게시물입니다.

Analysis of a PHP script that distributes Emotet malware.

https://andpalmier.github.io/posts/emotet-php-maldoc/

Emotet 악성 코드를 퍼뜨리는 PHP 스크립트 분석.

Which colour scheme is better?

https://stitcher.io/blog/why-light-themes-are-better-according-to-science

과학적으로는 다크 테마보다 밝은 테마가 좋다고 합니다.

Joe Watkins: Being Free

https://blog.krakjoe.ninja/2020/10/being-free.html

PHP가 20년 동안 어떻게 운영되고 있는지와 PHP를 지원할 수 있는 방안을 고민하는 글입니다.

📺 Videos

Profiling PHP applications with Xdebug

https://www.youtube.com/watch?v=mNc_tcomrVs

Xdebug의 저자인 Derick Rethans와 함께 하는, Xdebug로 PHP 어플리케이션을 프로파일링하는 90분짜리 동영상입니다.

Tutorial on starting with rectorphp/rector.

https://www.youtube.com/watch?v=_Uk95vG3ezQ

Compiling and test driving PHP 8

https://www.youtube.com/watch?v=tN4qs_FPkWQ

Brent Roose와 Freek Van der Herten이 PHP 8을 설치하고 새로운 기능을 살펴봅니다.

Deploy Friday #27 – Language Spotlight: PHP

https://www.youtube.com/watch?v=t8znkSvwQC8

Larry Garfield와 Patrick Dawkins이 진행하고 PHP 8 릴리스 매니저인 Sara Golemon과 Gabriel Caruso가 함께 하는 팟캐스트

🔈 Podcasts