PHP 7.2 Migraion

by Devellany

PHP /

PHP Supported Versions

VersionInitial ReleaseActive SupportSecurity Support
PHP 5.62014. 08. 28.2017. 01. 19.2018. 12. 31.
PHP 7.02015. 12. 03.2017. 12. 03.2018. 12. 03.
PHP 7.12016. 12. 01.2018. 12. 01.2019. 12. 01.
PHP 7.22017. 11. 30.2019. 11. 30.2020. 11. 30.
PHP 7.32018. 12. 06.2020. 12. 06.2021. 12. 06.

PHP Benchmarks

VersionREST APISmall overloadBig overload
PHP 5.61.4ms13.2ms128.5ms
PHP 7.00.3ms6.8ms80.5ms
PHP 7.10.4ms6.6ms80.1ms
PHP 7.20.3ms5.2ms68.7ms
PHP 7.30.4ms4.8ms65.2ms

PHP 7.2 기준 성능 비교

  • Small overload
  • PHP 7.1 대비 20% 향상
  • PHP 5.6 대비 131% 향상
  • Big overload
  • PHP 7.1 대비 14% 향상
  • PHP 5.6 대비 64% 향상

PHP 7.2 Migration

    정적 분석도구를 통하여 마이그레이션 준비

Migration Issue

  • mysql_* php5.5 deprecated, PHP 7.0 removed
    • mysqli_*
  • mysqli_*
  • split() PHP 5.3 deprecated, PHP 7.0 removed
    • preg_split()
  • preg_split()
  • ereg() PHP 5.3 deprecated, PHP 7.0 removed
    • preg_match()
  • preg_match()
  • each() PHP 7.2 deprecated
    • foreach()
  • foreach()
  • create_function() PHP 7.2 deprecated
    • Anonymous functions
  • Anonymous functions
  • $php_errormsg PHP 7.2 deprecated
    • error_get_last()
  • error_get_last()
  • PHP4 style class constructor PHP 7.0 not support
    • __construct
  • __construct
  • [] operator not supported for strings PHP 7.1 not support
    • 변수 초기화 변경
  • 변수 초기화 변경
  • Mcrypt PHP 7.1 deprecated, PHP 7.2 removed
    • Mcrypt 일부 암호화 알고리즘 OpenSSL로 복호화 가능
    • 복호화가 불가능한 경우 php.ini mcrypt.so 추가
  • Mcrypt 일부 암호화 알고리즘 OpenSSL로 복호화 가능
  • 복호화가 불가능한 경우 php.ini mcrypt.so 추가
  • 그 외
    • PHPExcel to PhpSpreadsheet
    • static function, public 선언
      • static function 접근제어자 미설정시 일부 환경에서 autoload 오류 발생
  • PHPExcel to PhpSpreadsheet
  • static function, public 선언
    • static function 접근제어자 미설정시 일부 환경에서 autoload 오류 발생
  • static function 접근제어자 미설정시 일부 환경에서 autoload 오류 발생

PHP 7.0-7.2 New Featrues

null 병합 연산자 (PHP 7.0)

// as-is
$msg = !empty($message) ? $message : 'not message';
// to-be
$msg = $message ?? 'not message';

우주선 연산자 (PHP 7.0)

echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1

메소드 파라미터/리턴 타입 선언 (PHP 7.0)

public function isLogin(): ?bool
{
    // 공통 타입
// CLASS_NAME, callable, string, int, bool, array, object(PHP 7.2)...
    // 리턴 전용 타입 void(PHP 7.1)
    // 리턴 타입 앞에 ? => 타입 or null(PHP 7.1)
}

스칼라타입 선언 (PHP 7.0)

function sumOfInts(int ...$ints)
{
    return array_sum($ints);
}
var_dump(sumOfInts(2, '3', 4.1)); // 9

상수 배열 선언 (PHP 7.0)

define('FRAMEWORK', [
    'Codeigniter',
    'Laravel',
    'Phalcon',
]);
echo FRAMEWORK[1]; // 'Laravel'

use 그룹화 (PHP 7.0)

use Vendor\ComponentA\{
    ClassA,
    ClassB,
    ClassC as Foo
};

암호화 알고리즘 Argon2 (PHP 7.2)

그 외 공식문서 참조

Author

Devellany

Devellany

back-end Developer

PHP, Java, JavaScript, MySQL, Redis, Ubuntu, Nginx
Codeigniter, Laravel, Zend, Phalcon, Spring Boot, JPA
PHPStorm, IntelliJ, Upsource, SVN, Git, Telegram Bot

로그인

디코에 오신 것을 환영해요!
전문가들의 수많은 아티클 창고 🤓