PHP 8.3: Class constant type declarations in some PHP extension classes

Version8.3
TypeChange

As a follow-up change to PHP supporting class constant types in PHP 8.3, Phar, SNMP, and Phar extension class constants are updated with constant types.

Any user-land PHP classes that extend the following classes and override existing constants will result in a fatal error.

It is uncommon for user-land PHP classes to extend these classes and override the constants.


Affected extensions:

Phar Extension class constant types

The Phar extension declares a Phar class that declares several class constants. In PHP 8.3, the Phar class constants are declared with a type.

  class Phar extends RecursiveDirectoryIterator implements Countable, ArrayAccess {

-    const BZ2 = UNKNOWN;
+    const int BZ2 = UNKNOWN;

-    const GZ = UNKNOWN;
+    const int GZ = UNKNOWN;

-    const NONE = UNKNOWN;
+    const int NONE = UNKNOWN;

-    const PHAR = UNKNOWN;
+    const int PHAR = UNKNOWN;

-    const TAR = UNKNOWN;
+    const int TAR = UNKNOWN;

-    const ZIP = UNKNOWN;
+    const int ZIP = UNKNOWN;

-    const COMPRESSED = UNKNOWN;
+    const int COMPRESSED = UNKNOWN;

-    const PHP = UNKNOWN;
+    const int PHP = UNKNOWN;

-    const PHPS = UNKNOWN;
+    const int PHPS = UNKNOWN;

-    const MD5 = UNKNOWN;
+    const int MD5 = UNKNOWN;

-    const OPENSSL = UNKNOWN;
+    const int OPENSSL = UNKNOWN;

-    const OPENSSL_SHA256 = UNKNOWN;
+    const int OPENSSL_SHA256 = UNKNOWN;

-    const OPENSSL_SHA512 = UNKNOWN;
+    const int OPENSSL_SHA512 = UNKNOWN;

-    const SHA1 = UNKNOWN;
+    const int SHA1 = UNKNOWN;

-    const SHA256 = UNKNOWN;
+    const int SHA256 = UNKNOWN;

-    const SHA512 = UNKNOWN;
+    const int SHA512 = UNKNOWN;

    // Rest of the Phar class
  }

Implementation

SNMP Extension class constant types

class SNMP {

-    public const VERSION_1 = UNKNOWN;
+    public const int VERSION_1 = UNKNOWN;

-    public const VERSION_2c = UNKNOWN;
+    public const int VERSION_2c = UNKNOWN;

-    public const VERSION_2C = UNKNOWN;
+    public const int VERSION_2C = UNKNOWN;

-    public const VERSION_3 = UNKNOWN;
+    public const int VERSION_3 = UNKNOWN;

-    public const ERRNO_NOERROR = UNKNOWN;
+    public const int ERRNO_NOERROR = UNKNOWN;

-    public const ERRNO_ANY = UNKNOWN;
+    public const int ERRNO_ANY = UNKNOWN;

-    public const ERRNO_GENERIC = UNKNOWN;
+    public const int ERRNO_GENERIC = UNKNOWN;

-    public const ERRNO_TIMEOUT = UNKNOWN;
+    public const int ERRNO_TIMEOUT = UNKNOWN;

-    public const ERRNO_ERROR_IN_REPLY = UNKNOWN;
+    public const int ERRNO_ERROR_IN_REPLY = UNKNOWN;

-    public const ERRNO_OID_NOT_INCREASING = UNKNOWN;
+    public const int ERRNO_OID_NOT_INCREASING = UNKNOWN;

-    public const ERRNO_OID_PARSING_ERROR = UNKNOWN;
+    public const int ERRNO_OID_PARSING_ERROR = UNKNOWN;

-    public const ERRNO_MULTIPLE_SET_QUERIES = UNKNOWN;
+    public const int ERRNO_MULTIPLE_SET_QUERIES = UNKNOWN;
      // Rest of the SNMP class
  }

Implementation

Zip Extension class constant types

The ZipArchive from the Zip extension also declares types for all of its class constants.

  class ZipArchive implements Countable {

-    public const CREATE = UNKNOWN;
+    public const int CREATE = UNKNOWN;

-    public const EXCL = UNKNOWN;
+    public const int EXCL = UNKNOWN;

-    public const CHECKCONS = UNKNOWN;
+    public const int CHECKCONS = UNKNOWN;

-    public const OVERWRITE = UNKNOWN;
+    public const int OVERWRITE = UNKNOWN;

-    public const RDONLY = UNKNOWN;
+    public const int RDONLY = UNKNOWN;

-    public const FL_NOCASE = UNKNOWN;
+    public const int FL_NOCASE = UNKNOWN;

-    public const FL_NODIR = UNKNOWN;
+    public const int FL_NODIR = UNKNOWN;

-    public const FL_COMPRESSED = UNKNOWN;
+    public const int FL_COMPRESSED = UNKNOWN;

-    public const FL_UNCHANGED = UNKNOWN;
+    public const int FL_UNCHANGED = UNKNOWN;

-    public const FL_RECOMPRESS = UNKNOWN;
+    public const int FL_RECOMPRESS = UNKNOWN;

-    public const FL_ENCRYPTED = UNKNOWN;
+    public const int FL_ENCRYPTED = UNKNOWN;

-    public const FL_OVERWRITE = UNKNOWN;
+    public const int FL_OVERWRITE = UNKNOWN;

-    public const FL_LOCAL = UNKNOWN;
+    public const int FL_LOCAL = UNKNOWN;

-    public const FL_CENTRAL = UNKNOWN;
+    public const int FL_CENTRAL = UNKNOWN;

-    public const FL_ENC_GUESS = UNKNOWN;
+    public const int FL_ENC_GUESS = UNKNOWN;

-    public const FL_ENC_RAW = UNKNOWN;
+    public const int FL_ENC_RAW = UNKNOWN;

-    public const FL_ENC_STRICT = UNKNOWN;
+    public const int FL_ENC_STRICT = UNKNOWN;

-    public const FL_ENC_UTF_8 = UNKNOWN;
+    public const int FL_ENC_UTF_8 = UNKNOWN;

-    public const FL_ENC_CP437 = UNKNOWN;
+    public const int FL_ENC_CP437 = UNKNOWN;

-    public const FL_OPEN_FILE_NOW = UNKNOWN;
+    public const int FL_OPEN_FILE_NOW = UNKNOWN;

-    public const CM_DEFAULT = UNKNOWN;
+    public const int CM_DEFAULT = UNKNOWN;

-    public const CM_STORE = UNKNOWN;
+    public const int CM_STORE = UNKNOWN;

-    public const CM_SHRINK = UNKNOWN;
+    public const int CM_SHRINK = UNKNOWN;

-    public const CM_REDUCE_1 = UNKNOWN;
+    public const int CM_REDUCE_1 = UNKNOWN;

-    public const CM_REDUCE_2 = UNKNOWN;
+    public const int CM_REDUCE_2 = UNKNOWN;

-    public const CM_REDUCE_3 = UNKNOWN;
+    public const int CM_REDUCE_3 = UNKNOWN;

-    public const CM_REDUCE_4 = UNKNOWN;
+    public const int CM_REDUCE_4 = UNKNOWN;

-    public const CM_IMPLODE = UNKNOWN;
+    public const int CM_IMPLODE = UNKNOWN;

-    public const CM_DEFLATE = UNKNOWN;
+    public const int CM_DEFLATE = UNKNOWN;

-    public const CM_DEFLATE64 = UNKNOWN;
+    public const int CM_DEFLATE64 = UNKNOWN;

-    public const CM_PKWARE_IMPLODE = UNKNOWN;
+    public const int CM_PKWARE_IMPLODE = UNKNOWN;

-    public const CM_BZIP2 = UNKNOWN;
+    public const int CM_BZIP2 = UNKNOWN;

-    public const CM_LZMA = UNKNOWN;
+    public const int CM_LZMA = UNKNOWN;

-    public const CM_LZMA2 = UNKNOWN;
+    public const int CM_LZMA2 = UNKNOWN;

-    public const CM_ZSTD = UNKNOWN;
+    public const int CM_ZSTD = UNKNOWN;

-    public const CM_XZ = UNKNOWN;
+    public const int CM_XZ = UNKNOWN;

-    public const CM_TERSE = UNKNOWN;
+    public const int CM_TERSE = UNKNOWN;

-    public const CM_LZ77 = UNKNOWN;
+    public const int CM_LZ77 = UNKNOWN;

-    public const CM_WAVPACK = UNKNOWN;
+    public const int CM_WAVPACK = UNKNOWN;

-    public const CM_PPMD = UNKNOWN;
+    public const int CM_PPMD = UNKNOWN;

-    public const ER_OK = UNKNOWN;
+    public const int ER_OK = UNKNOWN;

-    public const ER_MULTIDISK = UNKNOWN;
+    public const int ER_MULTIDISK = UNKNOWN;

-    public const ER_RENAME = UNKNOWN;
+    public const int ER_RENAME = UNKNOWN;

-    public const ER_CLOSE = UNKNOWN;
+    public const int ER_CLOSE = UNKNOWN;

-    public const ER_SEEK = UNKNOWN;
+    public const int ER_SEEK = UNKNOWN;

-    public const ER_READ = UNKNOWN;
+    public const int ER_READ = UNKNOWN;

-    public const ER_WRITE = UNKNOWN;
+    public const int ER_WRITE = UNKNOWN;

-    public const ER_CRC = UNKNOWN;
+    public const int ER_CRC = UNKNOWN;

-    public const ER_ZIPCLOSED = UNKNOWN;
+    public const int ER_ZIPCLOSED = UNKNOWN;

-    public const ER_NOENT = UNKNOWN;
+    public const int ER_NOENT = UNKNOWN;

-    public const ER_EXISTS = UNKNOWN;
+    public const int ER_EXISTS = UNKNOWN;

-    public const ER_OPEN = UNKNOWN;
+    public const int ER_OPEN = UNKNOWN;

-    public const ER_TMPOPEN = UNKNOWN;
+    public const int ER_TMPOPEN = UNKNOWN;

-    public const ER_ZLIB = UNKNOWN;
+    public const int ER_ZLIB = UNKNOWN;

-    public const ER_MEMORY = UNKNOWN;
+    public const int ER_MEMORY = UNKNOWN;

-    public const ER_CHANGED = UNKNOWN;
+    public const int ER_CHANGED = UNKNOWN;

-    public const ER_COMPNOTSUPP = UNKNOWN;
+    public const int ER_COMPNOTSUPP = UNKNOWN;

-    public const ER_EOF = UNKNOWN;
+    public const int ER_EOF = UNKNOWN;

-    public const ER_INVAL = UNKNOWN;
+    public const int ER_INVAL = UNKNOWN;

-    public const ER_NOZIP = UNKNOWN;
+    public const int ER_NOZIP = UNKNOWN;

-    public const ER_INTERNAL = UNKNOWN;
+    public const int ER_INTERNAL = UNKNOWN;

-    public const ER_INCONS = UNKNOWN;
+    public const int ER_INCONS = UNKNOWN;

-    public const ER_REMOVE = UNKNOWN;
+    public const int ER_REMOVE = UNKNOWN;

-    public const ER_DELETED = UNKNOWN;
+    public const int ER_DELETED = UNKNOWN;

-    public const ER_ENCRNOTSUPP = UNKNOWN;
+    public const int ER_ENCRNOTSUPP = UNKNOWN;

-    public const ER_RDONLY = UNKNOWN;
+    public const int ER_RDONLY = UNKNOWN;

-    public const ER_NOPASSWD = UNKNOWN;
+    public const int ER_NOPASSWD = UNKNOWN;

-    public const ER_WRONGPASSWD = UNKNOWN;
+    public const int ER_WRONGPASSWD = UNKNOWN;

-    public const ER_OPNOTSUPP = UNKNOWN;
+    public const int ER_OPNOTSUPP = UNKNOWN;

-    public const ER_INUSE = UNKNOWN;
+    public const int ER_INUSE = UNKNOWN;

-    public const ER_TELL = UNKNOWN;
+    public const int ER_TELL = UNKNOWN;

-    public const ER_COMPRESSED_DATA = UNKNOWN;
+    public const int ER_COMPRESSED_DATA = UNKNOWN;

-    public const ER_CANCELLED = UNKNOWN;
+    public const int ER_CANCELLED = UNKNOWN;

-    public const ER_DATA_LENGTH = UNKNOWN;
+    public const int ER_DATA_LENGTH = UNKNOWN;

-    public const ER_NOT_ALLOWED = UNKNOWN;
+    public const int ER_NOT_ALLOWED = UNKNOWN;

-    public const AFL_RDONLY = UNKNOWN;
+    public const int AFL_RDONLY = UNKNOWN;

-    public const AFL_IS_TORRENTZIP = UNKNOWN;
+    public const int AFL_IS_TORRENTZIP = UNKNOWN;

-    public const AFL_WANT_TORRENTZIP = UNKNOWN;
+    public const int AFL_WANT_TORRENTZIP = UNKNOWN;

-    public const AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE = UNKNOWN;
+    public const int AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE = UNKNOWN;

-    public const OPSYS_DOS = UNKNOWN;
+    public const int OPSYS_DOS = UNKNOWN;

-    public const OPSYS_AMIGA = UNKNOWN;
+    public const int OPSYS_AMIGA = UNKNOWN;

-    public const OPSYS_OPENVMS = UNKNOWN;
+    public const int OPSYS_OPENVMS = UNKNOWN;

-    public const OPSYS_UNIX = UNKNOWN;
+    public const int OPSYS_UNIX = UNKNOWN;

-    public const OPSYS_VM_CMS = UNKNOWN;
+    public const int OPSYS_VM_CMS = UNKNOWN;

-    public const OPSYS_ATARI_ST = UNKNOWN;
+    public const int OPSYS_ATARI_ST = UNKNOWN;

-    public const OPSYS_OS_2 = UNKNOWN;
+    public const int OPSYS_OS_2 = UNKNOWN;

-    public const OPSYS_MACINTOSH = UNKNOWN;
+    public const int OPSYS_MACINTOSH = UNKNOWN;

-    public const OPSYS_Z_SYSTEM = UNKNOWN;
+    public const int OPSYS_Z_SYSTEM = UNKNOWN;

-    public const OPSYS_CPM = UNKNOWN;
+    public const int OPSYS_CPM = UNKNOWN;

-    public const OPSYS_WINDOWS_NTFS = UNKNOWN;
+    public const int OPSYS_WINDOWS_NTFS = UNKNOWN;

-    public const OPSYS_MVS = UNKNOWN;
+    public const int OPSYS_MVS = UNKNOWN;

-    public const OPSYS_VSE = UNKNOWN;
+    public const int OPSYS_VSE = UNKNOWN;

-    public const OPSYS_ACORN_RISC = UNKNOWN;
+    public const int OPSYS_ACORN_RISC = UNKNOWN;

-    public const OPSYS_VFAT = UNKNOWN;
+    public const int OPSYS_VFAT = UNKNOWN;

-    public const OPSYS_ALTERNATE_MVS = UNKNOWN;
+    public const int OPSYS_ALTERNATE_MVS = UNKNOWN;

-    public const OPSYS_BEOS = UNKNOWN;
+    public const int OPSYS_BEOS = UNKNOWN;

-    public const OPSYS_TANDEM = UNKNOWN;
+    public const int OPSYS_TANDEM = UNKNOWN;

-    public const OPSYS_OS_400 = UNKNOWN;
+    public const int OPSYS_OS_400 = UNKNOWN;

-    public const OPSYS_OS_X = UNKNOWN;
+    public const int OPSYS_OS_X = UNKNOWN;

-    public const OPSYS_DEFAULT = UNKNOWN;
+    public const int OPSYS_DEFAULT = UNKNOWN;

-    public const EM_NONE = UNKNOWN;
+    public const int EM_NONE = UNKNOWN;

-    public const EM_TRAD_PKWARE = UNKNOWN;
+    public const int EM_TRAD_PKWARE = UNKNOWN;

-    public const EM_AES_128 = UNKNOWN;
+    public const int EM_AES_128 = UNKNOWN;

-    public const EM_AES_192 = UNKNOWN;
+    public const int EM_AES_192 = UNKNOWN;

-    public const EM_AES_256 = UNKNOWN;
+    public const int EM_AES_256 = UNKNOWN;

-    public const EM_UNKNOWN = UNKNOWN;
+    public const int EM_UNKNOWN = UNKNOWN;

-    public const LIBZIP_VERSION = UNKNOWN;
+    public const string LIBZIP_VERSION = UNKNOWN;

-    public const LENGTH_TO_END = UNKNOWN;
+    public const int LENGTH_TO_END = UNKNOWN;

-    public const LENGTH_UNCHECKED = UNKNOWN;
+    public const int LENGTH_UNCHECKED = UNKNOWN;-+

    // Rest of the ZipArchive class
  }

Implementation


Backward Compatibility Impact

This is a breaking change introduced in PHP 8.3. However, it is uncommon for user-land PHP applications to extend these classes and override these constants.

However, if a user-land PHP class extends these classes, and has a constant declaration for an existing name, the new declaration must include a class constant type, and must be compatible.

class ParentClass {
    public const string|int VALUE = 'MyValue';
}
class ChildClass extends ParentClass {
    public const VALUE = 'MyValue';
}
Fatal error: Type of ChildClass::VALUE must be compatible with ParentClass::VALUE of type string|int