From 8f175be188868adcfbf83da08a7455abf3f5246b Mon Sep 17 00:00:00 2001 From: haszi Date: Fri, 12 Dec 2025 22:53:53 +0100 Subject: [PATCH 1/4] Add test --- tests/GH-225.phpt | 26 ++++++++++++++++++++++++++ tests/data/bug-GH-225.xml | 2 ++ 2 files changed, 28 insertions(+) create mode 100644 tests/GH-225.phpt create mode 100644 tests/data/bug-GH-225.xml diff --git a/tests/GH-225.phpt b/tests/GH-225.phpt new file mode 100644 index 00000000..3fa20959 --- /dev/null +++ b/tests/GH-225.phpt @@ -0,0 +1,26 @@ +--TEST-- +GH-225 - SaveConfig tries to overwrite readonly property +--ARGS-- +--docbook tests/data/bug-GH-225.xml --quit +--FILE-- + 'Should not be imported', +);"); + +require_once __DIR__ . "/../render.php"; +?> +--CLEAN-- + +--EXPECTF-- +%s[%d:%d:%d - Heads up ]%s Loaded config from existing file diff --git a/tests/data/bug-GH-225.xml b/tests/data/bug-GH-225.xml new file mode 100644 index 00000000..b62ca013 --- /dev/null +++ b/tests/data/bug-GH-225.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file From f7726bf930228bf49c9fd769c2e685310035be3d Mon Sep 17 00:00:00 2001 From: haszi Date: Fri, 12 Dec 2025 22:54:31 +0100 Subject: [PATCH 2/4] Prevent serializing and deserializing non-serializable properties --- phpdotnet/phd/Config.php | 25 ++++++++++++++++++++++--- render.php | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/phpdotnet/phd/Config.php b/phpdotnet/phd/Config.php index 8c561c63..defc50c6 100644 --- a/phpdotnet/phd/Config.php +++ b/phpdotnet/phd/Config.php @@ -57,6 +57,15 @@ class Config public string $phpwebSourcesFilename = ''; public string $phpwebHistoryFilename = ''; + private const NON_SERIALIZABLE_PROPERTIES = [ + "copyright", + "indexCache", + "phpErrorOutput", + "userErrorOutput", + "phdInfoOutput", + "phdWarningOutput", + ]; + public function __construct() { $this->copyright = 'Copyright(c) 2007-' . \date('Y') . ' The PHP Documentation Group'; @@ -76,6 +85,10 @@ public function init(array $configOptions): void { throw new \Exception("Invalid option supplied: $option"); } + if (\in_array($option, self::NON_SERIALIZABLE_PROPERTIES, true)) { + continue; + } + $this->$option = $value; } @@ -83,12 +96,18 @@ public function init(array $configOptions): void { } /** - * Returns all configuration options and their values + * Returns all serializable configuration options and their values * * @return array */ - public function getAllFiltered(): array { - return \get_object_vars($this); + public function getAllSerializableProperties(): array { + $object_vars = \get_object_vars($this); + + foreach (self::NON_SERIALIZABLE_PROPERTIES as $property) { + unset($object_vars[$property]); + } + + return $object_vars; } /** diff --git a/render.php b/render.php index dbd451fa..be2d0c06 100644 --- a/render.php +++ b/render.php @@ -74,7 +74,7 @@ if ($config->saveConfig) { $outputHandler->v("Writing the config file", VERBOSE_MESSAGES); - file_put_contents("phd.config.php", "getAllFiltered(), 1) . ";"); + file_put_contents("phd.config.php", "getAllSerializableProperties(), 1) . ";"); } if ($config->quit) { From 9b5ca35c2c215538ffcbc0e776cd31040706cf14 Mon Sep 17 00:00:00 2001 From: haszi Date: Fri, 12 Dec 2025 23:12:09 +0100 Subject: [PATCH 3/4] Fix test --- tests/GH-225.phpt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/GH-225.phpt b/tests/GH-225.phpt index 3fa20959..174fbc80 100644 --- a/tests/GH-225.phpt +++ b/tests/GH-225.phpt @@ -6,6 +6,10 @@ GH-225 - SaveConfig tries to overwrite readonly property Date: Fri, 12 Dec 2025 23:20:28 +0100 Subject: [PATCH 4/4] Fix test - take 2 --- tests/GH-225.phpt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/GH-225.phpt b/tests/GH-225.phpt index 174fbc80..bf418192 100644 --- a/tests/GH-225.phpt +++ b/tests/GH-225.phpt @@ -6,8 +6,8 @@ GH-225 - SaveConfig tries to overwrite readonly property --EXPECTF-- %s[%d:%d:%d - Heads up ]%s Loaded config from existing file