[DOC-CVS] [phd] master: Add explicit type declarations to class constants (PHP 8.3+) (#215)

[email protected] (Louis-Arnaud via GitHub)
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: Louis-Arnaud (lacatoire)
Committer: GitHub (web-flow)
Pusher: Girgias
Date: 2026-02-05T20:45:10Z

Commit: https://github.com/php/phd/commit/c65199393a58de34ea583d1ead6623d844839902
Raw diff: https://github.com/php/phd/commit/c65199393a58de34ea583d1ead6623d844839902.diff

Add explicit type declarations to class constants (PHP 8.3+) (#215)

### Motivation
- Enhances type safety and static analysis.
- Makes code intent clearer.
- Prepares PhD for PHP 8.4 compatibility and future strictness.

### Scope
- Added types such as `int`, `string`, `bool`, or `array` to class constants.
- Example:
    Before:
        `public const FORMAT_HTML = 1;`
        `public const NAME = 'PhD';`
    After:
        `public const int FORMAT_HTML = 1;`
        `public const string NAME = 'PhD';`

### Impact
- ✅ No runtime behavior change.
- ✅ Fully backward compatible with PHP 8.3+.
- ⚙️ Code clarity and safety improvement only.
- Updated `composer.json` to indicate PHP 8.3 requirement
- Removed 8.1 and 8.2 CI pipelines

### References
- [PHP 8.3: Typed class constants RFC](https://wiki.php.net/rfc/typed_class_constants)
- [PHP manual: Class constants](https://www.php.net/manual/en/language.oop5.constants.php)

---------

Co-authored-by: lacatoire <[email protected]>

Changed paths:
  M  .github/workflows/ci.yml
  M  .github/workflows/test.yml
  M  composer.json
  M  composer.lock
  M  phpdotnet/phd/Config.php
  M  phpdotnet/phd/ErrorHandler.php
  M  phpdotnet/phd/Format.php
  M  phpdotnet/phd/OutputHandler.php
  M  phpdotnet/phd/Package/Generic/Manpage.php
  M  phpdotnet/phd/Package/IDE/API.php
  M  phpdotnet/phd/Package/PEAR/CHM.php
  M  phpdotnet/phd/Package/PHP/CHM.php
  M  phpdotnet/phd/Package/PHP/KDevelop.php
  M  phpdotnet/phd/Reader.php
  M  phpdotnet/phd/Render.php


Diff:

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 4025f1cc..d4e90132 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -4,7 +4,7 @@ jobs:
   ubuntu:
     strategy:
       matrix:
-          version: ['8.1', '8.2', '8.3', '8.4', '8.5']
+          version: ['8.3', '8.4', '8.5']
     runs-on: ubuntu-latest
     steps:
       - name: Checkout PhD
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index c964cbb5..3ea10364 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -5,7 +5,7 @@ jobs:
     name: test
     strategy:
       matrix:
-        version: ['8.1', '8.2', '8.3', '8.4', '8.5']
+        version: ['8.3', '8.4', '8.5']
     continue-on-error: ${{ matrix.version == '8.5' }}
     runs-on: ubuntu-latest
     steps:
diff --git a/composer.json b/composer.json
index 0ba62118..56806f44 100644
--- a/composer.json
+++ b/composer.json
@@ -18,7 +18,7 @@
         }
     ],
     "require": {
-        "php": ">=8.1.0",
+        "php": ">=8.3",
         "ext-dom": "*",
         "ext-sqlite3": "*",
         "ext-xmlreader": "*"
diff --git a/composer.lock b/composer.lock
index e36a46f7..41e6a930 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "7a1172b1a17b8a58fd3f50557a48316e",
+    "content-hash": "c0b6f4691ba3726550edf399f9af8ee6",
     "packages": [],
     "packages-dev": [],
     "aliases": [],
@@ -13,11 +13,11 @@
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": {
-        "php": ">=8.1.0",
+        "php": ">=8.3",
         "ext-dom": "*",
         "ext-sqlite3": "*",
         "ext-xmlreader": "*"
     },
     "platform-dev": {},
-    "plugin-api-version": "2.6.0"
+    "plugin-api-version": "2.9.0"
 }
diff --git a/phpdotnet/phd/Config.php b/phpdotnet/phd/Config.php
index 8c561c63..e23a8376 100644
--- a/phpdotnet/phd/Config.php
+++ b/phpdotnet/phd/Config.php
@@ -3,7 +3,7 @@
 
 class Config
 {
-    public const VERSION = '@phd_version@';
+    public const string VERSION = '@phd_version@';
     public readonly string $copyright;
 
     /** @var array<string, string> */
diff --git a/phpdotnet/phd/ErrorHandler.php b/phpdotnet/phd/ErrorHandler.php
index 202f4cf4..766eda6a 100644
--- a/phpdotnet/phd/ErrorHandler.php
+++ b/phpdotnet/phd/ErrorHandler.php
@@ -3,7 +3,7 @@
 
 class ErrorHandler
 {
-    private const ERROR_MAP = [
+    private const array ERROR_MAP = [
         // PHP Triggered Errors
         E_DEPRECATED                  => 'E_DEPRECATED          ',
         E_RECOVERABLE_ERROR           => 'E_RECOVERABLE_ERROR   ',
diff --git a/phpdotnet/phd/Format.php b/phpdotnet/phd/Format.php
index 2ac1d99d..53e5f211 100644
--- a/phpdotnet/phd/Format.php
+++ b/phpdotnet/phd/Format.php
@@ -10,7 +10,7 @@ abstract class Format extends ObjectStorage
      * @var    integer
      * @usedby createLink()
      */
-    const SDESC = 1;
+    const int SDESC = 1;
 
     /**
      * Represents a long description.
@@ -19,7 +19,7 @@ abstract class Format extends ObjectStorage
      * @var    integer
      * @usedby createLink()
      */
-    const LDESC = 2;
+    const int LDESC = 2;
 
     protected Config $config;
     protected OutputHandler $outputHandler;
diff --git a/phpdotnet/phd/OutputHandler.php b/phpdotnet/phd/OutputHandler.php
index 96da4c3e..0a878dfc 100644
--- a/phpdotnet/phd/OutputHandler.php
+++ b/phpdotnet/phd/OutputHandler.php
@@ -4,7 +4,7 @@
 class OutputHandler
 {
     /** @var array */
-    private const CONSTANT_TO_MESSAGE_CATEGORY_MAP = [
+    private const array CONSTANT_TO_MESSAGE_CATEGORY_MAP = [
         // PhD informationals
         VERBOSE_INDEXING              => 'Indexing              ',
         VERBOSE_FORMAT_RENDERING      => 'Rendering Format      ',
diff --git a/phpdotnet/phd/Package/Generic/Manpage.php b/phpdotnet/phd/Package/Generic/Manpage.php
index d4b86364..201578cc 100644
--- a/phpdotnet/phd/Package/Generic/Manpage.php
+++ b/phpdotnet/phd/Package/Generic/Manpage.php
@@ -2,8 +2,8 @@
 namespace phpdotnet\phd;
 
 class Package_Generic_Manpage extends Format_Abstract_Manpage {
-    const OPEN_CHUNK    = 0x01;
-    const CLOSE_CHUNK   = 0x02;
+    const int OPEN_CHUNK    = 0x01;
+    const int CLOSE_CHUNK   = 0x02;
 
      private $elementmap = array( /* {{{ */
         'acronym'               => 'format_suppressed_tags',
diff --git a/phpdotnet/phd/Package/IDE/API.php b/phpdotnet/phd/Package/IDE/API.php
index 73bc7302..f4ba6955 100644
--- a/phpdotnet/phd/Package/IDE/API.php
+++ b/phpdotnet/phd/Package/IDE/API.php
@@ -35,14 +35,14 @@ class Package_IDE_API
      *
      * @var string
      */
-    const FUNCTIONS_DIR = 'ide-xml';
+    const string FUNCTIONS_DIR = 'ide-xml';
 
     /**
      * Output file of the funclist format in the IDE Package.
      *
      * @var string
      */
-    const FUNCLIST_FILE = 'ide-funclist.txt';
+    const string FUNCLIST_FILE = 'ide-funclist.txt';
 
     /**
      * PhD output directory.
diff --git a/phpdotnet/phd/Package/PEAR/CHM.php b/phpdotnet/phd/Package/PEAR/CHM.php
index d016be5b..c116264b 100755
--- a/phpdotnet/phd/Package/PEAR/CHM.php
+++ b/phpdotnet/phd/Package/PEAR/CHM.php
@@ -2,8 +2,8 @@
 namespace phpdotnet\phd;
 
 class Package_PEAR_CHM extends Package_PEAR_ChunkedXHTML {
-    const DEFAULT_FONT = "Arial,10,0";
-    const DEFAULT_TITLE = "PEAR Manual";
+    const string DEFAULT_FONT = "Arial,10,0";
+    const string DEFAULT_TITLE = "PEAR Manual";
 
     // Array to manual code -> HTML Help Code conversion
 	// Code list: http://www.helpware.net/htmlhelp/hh_info.htm
diff --git a/phpdotnet/phd/Package/PHP/CHM.php b/phpdotnet/phd/Package/PHP/CHM.php
index 86d9c445..7da2be4a 100644
--- a/phpdotnet/phd/Package/PHP/CHM.php
+++ b/phpdotnet/phd/Package/PHP/CHM.php
@@ -3,8 +3,8 @@
 
 class Package_PHP_CHM extends Package_PHP_ChunkedXHTML
 {
-    const DEFAULT_FONT = "Arial,10,0";
-    const DEFAULT_TITLE = "PHP Manual";
+    const string DEFAULT_FONT = "Arial,10,0";
+    const string DEFAULT_TITLE = "PHP Manual";
 
     // Array to manual code -> HTML Help Code conversion
     // Code list: http://www.helpware.net/htmlhelp/hh_info.htm
diff --git a/phpdotnet/phd/Package/PHP/KDevelop.php b/phpdotnet/phd/Package/PHP/KDevelop.php
index 5783e898..168658d1 100644
--- a/phpdotnet/phd/Package/PHP/KDevelop.php
+++ b/phpdotnet/phd/Package/PHP/KDevelop.php
@@ -2,7 +2,7 @@
 namespace phpdotnet\phd;
 
 class Package_PHP_KDevelop extends Format {
-    const DEFAULT_HREF = "http://www.php.net/manual/en/";
+    const string DEFAULT_HREF = "http://www.php.net/manual/en/";
 
     protected $elementmap = array(
         'book'                  => 'format_tocsect1',
diff --git a/phpdotnet/phd/Reader.php b/phpdotnet/phd/Reader.php
index 47240f14..dbce53a1 100644
--- a/phpdotnet/phd/Reader.php
+++ b/phpdotnet/phd/Reader.php
@@ -3,11 +3,11 @@
 
 class Reader extends \XMLReader
 {
-    const XMLNS_XML     = "http://www.w3.org/XML/1998/namespace";
-    const XMLNS_XLINK   = "http://www.w3.org/1999/xlink";
-    const XMLNS_PHD     = "http://www.php.net/ns/phd";
-    const XMLNS_DOCBOOK = "http://docbook.org/ns/docbook";
-    const XMLNS_MATHML  = "http://www.w3.org/1998/Math/MathML";
+    const string XMLNS_XML     = "http://www.w3.org/XML/1998/namespace";
+    const string XMLNS_XLINK   = "http://www.w3.org/1999/xlink";
+    const string XMLNS_PHD     = "http://www.php.net/ns/phd";
+    const string XMLNS_DOCBOOK = "http://docbook.org/ns/docbook";
+    const string XMLNS_MATHML  = "http://www.w3.org/1998/Math/MathML";
     
     protected OutputHandler $outputHandler;
 
diff --git a/phpdotnet/phd/Render.php b/phpdotnet/phd/Render.php
index eeacc68e..dc7c7550 100644
--- a/phpdotnet/phd/Render.php
+++ b/phpdotnet/phd/Render.php
@@ -3,13 +3,13 @@
 
 class Render extends ObjectStorage
 {
-    const CHUNK        = 0x001;
-    const OPEN         = 0x002;
-    const CLOSE        = 0x004;
-    const STANDALONE   = 0x008;
-    const INIT         = 0x010;
-    const FINALIZE     = 0x020;
-    const VERBOSE      = 0x040;
+    const int CHUNK        = 0x001;
+    const int OPEN         = 0x002;
+    const int CLOSE        = 0x004;
+    const int STANDALONE   = 0x008;
+    const int INIT         = 0x010;
+    const int FINALIZE     = 0x020;
+    const int VERBOSE      = 0x040;
 
     private   $STACK      = array();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.