theseer / phpdox

Documentation generator for PHP Code using standard technology (SRC, DOCBLOCK, XML and XSLT)
http://phpdox.de
Other
601 stars 121 forks source link

fdomdocument issue on PHP 8.2 #424

Open dereckson opened 1 year ago

dereckson commented 1 year ago

PHP 8.2 adds a new deprecation to the archive fdomdocument library, which breaks phpdox:

PHP Version: 8.2.4 (Linux)
PHPDox Version: eb943cb-dirty
ErrorException: E_DEPRECATED
Location: /opt/phpdox/vendor/theseer/fdomdocument/src/fDOMDocument.php (Line 251)

DOMDocument::save(): Passing null to parameter #2 ($options) of type int is deprecated

No stacktrace available

The DOMDocument::save signature is:

public DOMDocument::save(string $filename, int $options = 0): int|false

Library is documented to still work on PHP 7, so this isn't a proper fix, but last year I used this code on a development server to fix all deprecations:

            $tmp = match ($options) {
                NULL => parent::save($filename),
                default => parent::save($filename, $options),
            };

To stay compatible with PHP 7, and as 0 is the default value for $options, could we have more simply this instead?

diff --git a/src/fDOMDocument.php b/src/fDOMDocument.php
index 52f9df0..9ca04a6 100644
--- a/src/fDOMDocument.php
+++ b/src/fDOMDocument.php
@@ -247,7 +247,7 @@ namespace TheSeer\fDOM {
          * @return integer bytes saved
          */
         #[\ReturnTypeWillChange]
-        public function save($filename, $options = NULL) {
+        public function save($filename, $options = 0) {
             $tmp = parent::save($filename, $options);
             if (!$tmp) {
                 throw new fDOMException("Saving XML to file '$filename' failed", fDOMException::SaveError);
dereckson commented 1 year ago

Tested on our CI infrastructure the second simplest solution, seems to work well.

theseer commented 1 year ago

I'll have a look upcoming week. Sounds like something we could be doing.