php-annotated-monthly-august-2019

Php_annotated_monthly 이미지

Roman Pronskiy가 쓰고 JetBrains에서 제공하는 월간 PHP Annotated Monthly 2019년 8월호입니다.

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


⚡️ News & Releases

PSR-12 Extended Coding Style Guide

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md

PSR-12가 정식 표준이 되었습니다. PSR-2에 비해 변경된 점은 여기를 참고하세요. 새로 추가된 부분은 아래와 같습니다.

  • Lowercase for all keywords - Section 2.5
  • Short form for all type keywords - Section 2.5
  • Use statement grouping - Section 3
  • Use statement blocks - Section 3
  • Declare statement/Strict types declaration usage - Section 3
  • Parentheses are always required for class instantiation - Section 4
  • Typed properties - Section 4.3
  • Return type declarations - Section 4.5
  • Variadic and reference argument operators - Section 4.5
  • Type hints - Section 4.5
  • Add finally block - Section 5.6
  • Operators - Section 6
  • Unary operators - Section 6.1
  • Binary operators - Section 6.2
  • Ternary operators - Section 6.3
  • Anonymous classes - Section 8

PHP 7.4.0 beta 2

https://www.php.net/archive/2019.php#2019-08-08-1

PHP 7.4.0 beta 2가 나왔습니다. 이제 활발히 개발되는 단계는 지났습니다. 여기 새 기능 목록이 최종 기능으로 고려되고 있습니다. extension 개발자들은 internal API changes 목록을 확인해보시는 게 좋겠습니다.

PHP 7.3.8, 7.2.21, 7.1.31

나왔어요. 나왔어요. 나왔어요.

Slim 4.0.0

얘도요.

Composer 1.9.0

https://github.com/composer/composer/releases/tag/1.9.0

release note를 한번 볼까요?

  • Added a –no-cache flag available on all commands to run with the cache disabled
  • Added PHP_BINARY as env var pointing to the PHP process when executing Composer scripts as shell scripts
  • Added a use-github-api config option which can set the no-api flag on all GitHub VCS repositories declared
  • Added a static helper you can preprend to a script to avoid process timeouts, “Composer\Config::disableProcessTimeout”
  • Added Event::getOriginatingEvent to retrieve an event’s original event when a script handler forwards to another one
  • Added support for autoloading directly from a phar file
  • Fixed loading order of plugins to always initialize them in order of dependencies
  • Fixed various network-mount related issues
  • Fixed –ignore-platform-reqs not ignoring conflict rules against platform packages

🐘 PHP Internals

P++

https://externals.io/message/106453

PHP Internals에서 removal of short tags <?이나 explicit call-site send-by-ref syntax과 같은 제안에서는 논쟁이 매우 격화된 바 있습니다. 하위 호환을 유지하는 것과 새로운 기능을 넣거나 강력한 타입을 도입하는 것 사이에 마찰이 심했던 것으로 보입니다. Zeev Suraski란 사람이 결국 새로운 PHP 방언(dialect)를 만들자고 제안까지 했습니다. 확정은 아니지만 우선 P++이라는 이름인데 C와 C++의 관계에서 차용한 것으로 보이고, 하나의 런타임에서 PHP와 P++을 동신에 실행하는 것을 제안했습니다.

P++이 받아들여진다면 PHP에서는 여전히 문법과 관련없는 기능 업데이트나 속도와 하위 호환성을 얻을 수 있을 것이고, P++은 하위 호환성을 유지할 필요없이 깨끗하게 legacy를 걷어내고 혁신적인 기능을 구현해나갈 수 있게 됩니다.

Zeev가 올린 P++ idea: FAQ에는 수많은 반대/우려 글이 올라오고 있습니다. PHP에 fulltime으로 일하는 사람이 2명 뿐이고, 커뮤니티의 분열, Hack에서의 경험, 어떻게 PHP와 P++ 코드가 공존하고 상호작용할 수 있겠는가 등. 이외에도 여기, 저기에 많은 논쟁이 일어나고 있습니다.

P++의 이해를 돕기 위해 FAQ 페이지에 나온 이야기 몇개를 소개하자면,

예전에 Nikita Popov가 Rust처럼 Editions을 도입하자고 주장하기도 했는데, 이게 현재를 legacy를 보고 호환성을 끊고 나가겠다는 의미라면, P++은 동적이고 유연한 PHP와 함께 공존한다는 점에서 가장 크게 다릅니다.

그럼 또 하나의 Hack이 나오는 게 아니냐라는 질문에, Hack의 경우에는 하나의 기업에서 관리하면서 커뮤니티가 지원하기도 어려웠고, PHP의 거대한 배포 수단이 없었기에 널리 퍼지기도 쉽지 않았습니다. P++은 PHP와 동일한 런타임으로 제공되기 때문에 쓰지 않더라도 사용할 수 있는 기반은 되는 셈입니다.

사실 이 제안은 P++ 하나 만이 아니라 여러 버전의 방언이 하나의 런타임에서 동시에 제공되는 그림을 그리고 있는데요. 댓글 중에는 결국 그 중에 하나만이 살아남을 것이고 커뮤니티는 파편화 되고, 결국 당장 인기있는 버전만을 신경쓰게 될 것을 우려하고 있습니다.

[RFC] Namespace-scoped declares, again

https://externals.io/message/101323#106345

이 RFC가 위에서 ‘Nikita Popov가 Rust처럼 Editions…’라고 언급된 곳입니다. 링크를 따라가면 Nikita의 댓글이 보이는데, 여기서 두가지를 언급합니다.

하나는 언어의 진화 과정에서 (이 제안처럼) strict_types과 같은 개별 설정을 하나씩 추가해 나갈 것인가, Rust의 Editions처럼 ‘PHP 2020’과 같은 하나의 에디션으로 여러 변경 사항을 묶어서 적용할 것인가입니다. 오래된 문제를 해결하면서도 하위 호환을 무너뜨리지 않기 위한 많은 고민이 보입니다.

그리고 또 하나는 이 세부 구현을 어떻게 하위 호환을 깨뜨리지 않고 구현할 것인가에 대한 고민입니다. 제안은 namespace 단위로 strict_types과 같은 설정을 하는 것인데, 다른 방식으로도 검토했던 내용이 담겨 있습니다.

Call for participation: Annotating internal function argument and return types

https://externals.io/message/106522

PHP core에 contributor가 되고 싶으셨다면, 지금보다 좋을 때는 없을 겁니다.

Reflection의 내부 함수에 type 정보가 부족하다는 것은 오래된 이슈입니다. PHP8에서는 argument와 return type에 대한 annotation을 제공하기 위한 기본 작업은 다 되었는데, 실제로 수백개의 함수에 그걸 추가하는 것이 필요하다고 합니다.

위의 externals.io 링크를 따라가면 샘플 PR과 함게 어떻게 하면 되는지 알려줍니다.

🛠 Tools

krakjoe/tombs

https://github.com/krakjoe/tombs

죽은 코드를 찾아내는 라이브러리입니다. 이 코드를 퍼포먼스 저하 걱정없이 프로덕션에 넣기만 하고, 하루든 일주일이든 한달이든 기다렸다가, 어떤 함수가 한번도 실행되지 않았는지 확인하시면 됩니다. 어떻게 가능한지는 Joe Watkins의 blog post를 확인해보세요.

krakjoe/stat

https://github.com/krakjoe/stat

병렬 쓰레드에서 동작하는 Joe Watkins의 또 다른 프로파일링 extension입니다. 역시 자세한 건 Joe Watkins의 또 다른 blog post를 확인하세요.

nunomaduro/pest

https://github.com/nunomaduro/pest

PHPUnit에서 facebook/jest 스타일로 테스트를 쓸 수 있게 해줍니다.

mpratt/Embera

https://github.com/mpratt/Embera

Embera는 Oembed consumer library입니다. 텍스트에서 특정 서비스의 URL이 발견되면 embed code를 만들어주는 등 해당 미디어의 정보를 가져옵니다.

NxtLvLSoftware/php-static-constructors

https://github.com/NxtLvLSoftware/php-static-constructors

C#의 Static constructors와 같은 개념이랍니다.

exussum12/coverageChecker

https://github.com/exussum12/coverageChecker

전체 코드베이스가 아닌 신규나 변경된 코드에 대해서만 특정 커버리지 이상을 유지할 수 있게 도와주는 툴입니다.

DaveLiddament/sarb

https://github.com/DaveLiddament/sarb

A similar tool that implements a Baseline feature for the quality analysis tools, which allows to use them in legacy-applications.

Symfony

SymfonyCloud

https://symfony.com/blog/symfonycloud-from-early-access-to-general-availability

The service for Symfony applications deployment has come out of beta and is now available to everyone. It allows you to describe the infrastructure in yaml configs and then deploy, update, take snapshots, etc. with one command. See an example of how it was used for redirection.io.

Minor non-LTS releases of Symfony will be supported for 8 months instead of 14.

https://symfony.com/blog/symfony-maintenance-changes-for-standard-releases

A week of Symfony #658 (5-11 August 2019)

https://symfony.com/blog/a-week-of-symfony-658-5-11-august-2019

Decouple your Symfony application using Domain Events

https://romaricdrigon.github.io/2019/08/09/domain-events

Laravel

🎥 Taylor’s talk at Laracon US:

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

• Laravel 6 will be released in August
• The framework will move to Semver (components already follow it)
• New branding
Laravel New branding
• Laravel Vapor announced – A paid service for deploying Laravel-application in AWS infrastructure: Lambda, RDS, CloudFront, S3, and CloudWatch. It comes with a hosted web interface and a CLI tool for configuring, deploying, and monitoring applications. Neat!

What is AWS Lambda and how Laravel Vapor uses it.

https://divinglaravel.com/what-is-aws-lambda-and-how-laravel-vapor-uses-it

맨 처음 Lambda Layers가 발표됐을 때 SAM 기반으로 PHP 어플리케이션을 띄울 수 있게 해준 Bref와의 차이가 뭐냐는 질문에 Taylor Otwell은 아래와 같이 답했습니다.

Yes a bit different… the whole setup is custom and not based on SAM or Serverless Framework… queue and web are separate lambdas… we have a few PHP extensions that are not on Bref runtime such as GD

🎥 Simplification Tips and Tricks (Laracon 2019)

https://www.youtube.com/watch?v=FxACh4X-Xc0

calebporzio/livewire

https://github.com/calebporzio/livewire

A frontend framework for Laravel that allows you to write bindings in Blade directly to PHP-classes without having to write any additional JS code.

ylsideas/feature-flags

https://github.com/ylsideas/feature-flags

A Laravel package for handling feature flags.

Lower time testing existing Laravel application

https://jasonmccreary.me/articles/lower-time-testing-existing-laravel-application/

Service locator: an anti-pattern

https://stitcher.io/blog/service-locator-anti-pattern

1년 전에 작성된 글이고 전에도 한번 소개됐던 것 같은 기분이지만, 중요하다면 계속 들어도 좋겠죠. 저자는 Service locator의 아래와 같은 문제를 지적합니다.

  • 런타임 오류 가능성이 더 큽니다
  • 코드는 외부로 난독 처리됩니다
  • 인지 부하를 증가시킵니다

🌀 Async PHP

🎥 Creating a RESTful API with ReactPHP

https://www.youtube.com/watch?v=aR3e9pj9TIo&list=PLKIEFFgNQYpWeEvjglhMKUsM1xxKAwgcs

Serverless

Deploying Laravel Artisan on AWS Lambda with bref.

https://blog.deleu.dev/deploying-laravel-artisan-on-aws-lambda/

위 Vapor에서 언급됐던 Bref로 Laravel Artisan을 람다에 올리는 방법입니다.

Another case study for using AWS Lambda and bref.

https://blog.servmask.com/serverless-for-php-developers/

Bref를 활용한 또 다른 사례 연구

Serverless PHP on App Engine + Cloud Firestore and Firevel.

https://medium.com/firebase-developers/serverless-php-on-app-engine-firestore-c22a119dc608

Google App Engine에서 PHP를 실행할 수 있게, Laravel을 수정한 Firevel을 소개합니다. Firestore를 DB와 캐시로 사용합니다. Eloquent가 NoSQL을 고려하지 않았기 때문에 이에 대응하는 Firequent라는 패키지도 개발했다고 합니다.

Firevel 에 포함 된 패키지는 다음과 같습니다.

💡 기타 읽을 만한 글

Dividing responsibilities

https://matthiasnoback.nl/2019/07/dividing-responsibilities-part-1/

Mathias Noback이란 사람의 새 책의 일부 챕터입니다.

책임 분리를 다루면서 읽기와 쓰기 모델을 분리하는 과정을 보여줍니다.

How to write cloud native and container ready PHP applications

https://withblue.ink/2019/07/24/cloud-native-container-ready-php.html

사람들은 여전히 PHP를 싫어한다면서, “PHP는 섹시하지는 않지만 여전히 웹을 지배합니다.”라고 운을 뗍니다.

PHP가 cloud native하게 개발하는데 문제가 되는 부분은 없으나, …??

(지난 20년 동안의 전통적인 PHP 개발 관행에 위배되는) cloud native PHP application를 설계할 때 중요한 4가지를 지적하고 싶다고 합니다.

  1. 로컬 파일 시스템에서 멀어져야 합니다
  2. 세션 정보를 Redis에 저장해야 합니다
  3. 설정 파일을 환경 변수로 대체해야 합니다
  4. built-in 인스톨러나 updater를 사용하면 안됩니다

두번째 항목에서는 꼭 Redis만을 써야 한다는 말은 아니고 세션서버를 분리해야 한다는 의미입니다.

PHP 앱을 컨테이너화하는 방법에서는 Nginx + PHP-FPM 조합보다 Apache 웹 서버와 mod_php를 추천하고 있습니다. Nginx가 정적 리소스를 제공하는데 훨씬 유리한 면이 있지만 PHP 앱은 보통 API 서버로 동작하며 정적 리소스는 CDN을 통해 제공하므로, 관리 측면에서 Apache + mod_php가 유리하다는 의견입니다.

I wrote a PHPStorm plugin

https://dev.to/kristijankanalas/i-wrote-a-phpstorm-plugin-1job

How to create a PhpStorm plugin that adds more code generation capabilities.

PhpStorm plugin을 제작한 경험입니다. 자랑스러운 코드는 아니라고 합니다. :)

How we completed thousands of missing @var annotations in a day

https://www.tomasvotruba.cz/blog/2019/07/29/how-we-completed-thousands-of-missing-var-annotations-in-a-day/

@var에 의존하는 PHPStan의 정적 분석을 사용하기 위해, 하루 안에, 코드를 수동으로 변경하지 않고 @var annotation을 추가한 과정을 설명합니다.

Accessing private properties without Reflection

https://twitter.com/mindplaydk/status/1158995315124559872

Reflection 없이 private property를 읽는 방법입니다.

function inspect($object, $property) {
return (function () use ($property) {
return $this->$property;
})->call($object);
}

오래된 트릭을 훌륭하게 응용했네요.

PHP 버전 별 실행 결과(https://3v4l.org/lqZBd )를 보시면 PHP 7.0 이상에서만 가능한 것으로 보입니다.

🔈 Podcasts

🔈 PHP Internals News #20

  • With Nikita Popov about improvements to test PHP on many more platforms and in many more configurations.

🔈 PHP Internals News #21

  • With Will Hudgins about his “Add str_starts_with(), str_ends_with() and related functions” RFC.

🔈 PHP Internals News #22

  • With Matteo Beccati about his RFC “Escape PDO “?” parameter placeholder”.

🔈 That Podcast Episode 63

  • With Benjamin Eberlei about Tideways.