PHP7.2 이전 버전과 호환되지 않는 변경 사항

Prevent number_format() from returning negative zero

이전에는 number_format() 함수가 -0을 반환할 수 있었습니다. 이것은 IEEE 754 부동 소수점 사양에 따라 완벽하게 유효하지만 이 이상한 점은 형식이 지정된 숫자를 사람이 읽을 수 있는 형식으로 표시하는 데 바람직하지 않습니다.

                  
<?php

// array to object
$arr = [0 => 1];
$obj = (object)$arr;
var_dump(
    $obj,
    $obj->{'0'}, // now accessible
    $obj->{0} // now accessible
);
                  
                

위의 예는 다음을 출력합니다.

object(stdClass)#1 (1) {
  ["0"]=>    // string key now, rather than integer key
  int(1)
}
int(1)
int(1)
                

이제 배열로 캐스트되는 객체의 정수(또는 문자열 정수) 키에 액세스할 수 있습니다.

                  
<?php

// object to array
$obj = new class {
    public function __construct()
    {
        $this->{0} = 1;
    }
};
$arr = (array)$obj;
var_dump(
    $arr,
    $arr[0], // now accessible
    $arr['0'] // now accessible
);
                  
                

위의 예는 다음을 출력합니다.

array(1) {
  [0]=>    // integer key now, rather than string key
  int(1)
}
int(1)
int(1)
                

Disallow passing null to get_class()

이전에는 get_class() 함수에 null을 전달하면 포함하는 클래스의 이름이 출력되었습니다. 이 동작은 이제 제거되었으며 E_WARNING이 대신 출력됩니다. 이전과 동일한 동작을 수행하려면 인수를 생략하면 됩니다.


Warn when counting non-countable types

이제 E_WARNING이 계산할 수 없는 유형을 count()하려고 할 때 발생합니다(여기에는 sizeof() 별칭 함수 포함).

                  
<?php

var_dump(
    count(null), // NULL is not countable
    count(1), // integers are not countable
    count('abc'), // strings are not countable
    count(new stdclass), // objects not implementing the Countable interface are not countable
    count([1,2]) // arrays are countable
);
                  
                

위의 예는 다음을 출력합니다.

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d
int(0)
int(1)
int(1)
int(1)
int(2)
                

Move ext/hash from resources to objects

리소스에서 멀리 떨어진 장기 마이그레이션의 일환으로 Hash 확장이 리소스 대신 개체를 사용하도록 업데이트되었습니다. is_resource() 검사가 수행된 위치(대신 is_object()로 업데이트해야 함)를 제외하고 PHP 개발자에게 변경 사항이 원활해야 합니다.


Improve SSL/TLS defaults

기본값이 다음과 같이 변경되었습니다.

  • tls:// now defaults to TLSv1.0 or TLSv1.1 or TLSv1.2
  • ssl:// an alias of tls://
  • STREAM_CRYPTO_METHOD_TLS_* constants default to TLSv1.0 or TLSv1.1 + TLSv1.2, instead of TLSv1.0 only

gettype() return value on closed resources

이전에는 닫힌 리소스에서 gettype()을 사용하면 "알 수 없는 유형" 문자열이 반환되었습니다. 이제 "resource (closed)" 문자열이 반환됩니다.


is_object() and __PHP_Incomplete_Class

이전에는 __PHP_Incomplete_Class 클래스에서 is_object()를 사용하면 false가 반환되었습니다. 이제 true가 반환됩니다.


Promote the error level of undefined constants

정의되지 않은 상수에 대한 규정되지 않은 참조는 이제 E_NOTICE 대신 E_WARNING을 생성합니다. PHP의 다음 주요 버전에서는 ,a href="class.error.php">오류 예외가 생성됩니다.


Windows support

공식적으로 지원되는 최소 Windows 버전은 이제 Windows 7/Server 2008 R2입니다.


Checks on default property values of traits

기본 특성 속성 값에 대한 호환성 검사는 더 이상 캐스팅을 수행하지 않습니다.


object for class names

객체 이름은 이전에 PHP 7.0에서 소프트 예약되었습니다. 이것은 이제 하드 예약되어 클래스, 특성 또는 인터페이스 이름으로 사용되는 것을 금지합니다.


NetWare support

NetWare에 대한 지원이 이제 제거되었습니다.


array_unique() with SORT_STRING

SORT_STRING이 있는 array_unique()는 이전에 배열을 복사하고 고유하지 않은 요소를 제거했지만(나중에 배열을 패킹하지 않고) 이제 고유 요소를 추가하여 새 배열을 만듭니다. 이로 인해 다른 숫자 인덱스가 생성될 수 있습니다.


bcmod() changes with floats

bcmod() 함수는 더 이상 분수를 정수로 자르지 않습니다. 따라서 그 동작은 이제 % 연산자가 아닌 fmod()를 따릅니다. 예를 들어 bcmod('4', '3.5')는 이제 1 대신 0.5를 반환합니다.


Hashing functions and non-cryptographic hashes

hash_hmac(), hash_hmac_file(), hash_pbkdf2()hash_init()(HASH_HMAC 포함) 함수는 더 이상 비암호화 해시를 허용하지 않습니다.


json_decode() function options

json_decode() 함수 옵션인 JSON_OBJECT_AS_ARRAY는 이제 두 번째 매개변수(assoc)가 null인 경우 사용됩니다. 이전에는 JSON_OBJECT_AS_ARRAY가 항상 무시되었습니다.


rand() and mt_rand() output

특정 시드에 대해 rand()mt_rand()에 의해 생성된 시퀀스는 64비트 시스템의 PHP 7.1과 다를 수 있습니다(구현에서 모듈로 바이어스 버그 수정으로 인해).


Removal of sql.safe_mode ini setting

sql.safe_mode ini 설정이 이제 제거되었습니다.


Changes to date_parse() and date_parse_from_format()

date_parse()date_parse_from_format()이 반환하는 배열의 zone 요소는 현재 분이 아닌 초를 나타내며 부호가 반전됩니다. 예를 들어 -120은 이제 7200입니다.


Incoming Cookies

PHP 7.2.34부터 보안상의 이유로 들어오는 쿠키의 이름이 더 이상 URL 디코딩되지 않습니다.