Skip to content

Commit f7726bf

Browse files
author
haszi
committed
Prevent serializing and deserializing non-serializable properties
1 parent 8f175be commit f7726bf

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

phpdotnet/phd/Config.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ class Config
5757
public string $phpwebSourcesFilename = '';
5858
public string $phpwebHistoryFilename = '';
5959

60+
private const NON_SERIALIZABLE_PROPERTIES = [
61+
"copyright",
62+
"indexCache",
63+
"phpErrorOutput",
64+
"userErrorOutput",
65+
"phdInfoOutput",
66+
"phdWarningOutput",
67+
];
68+
6069
public function __construct() {
6170
$this->copyright = 'Copyright(c) 2007-' . \date('Y') . ' The PHP Documentation Group';
6271

@@ -76,19 +85,29 @@ public function init(array $configOptions): void {
7685
throw new \Exception("Invalid option supplied: $option");
7786
}
7887

88+
if (\in_array($option, self::NON_SERIALIZABLE_PROPERTIES, true)) {
89+
continue;
90+
}
91+
7992
$this->$option = $value;
8093
}
8194

8295
\error_reporting($GLOBALS['olderrrep'] | $this->verbose);
8396
}
8497

8598
/**
86-
* Returns all configuration options and their values
99+
* Returns all serializable configuration options and their values
87100
*
88101
* @return array<string, mixed>
89102
*/
90-
public function getAllFiltered(): array {
91-
return \get_object_vars($this);
103+
public function getAllSerializableProperties(): array {
104+
$object_vars = \get_object_vars($this);
105+
106+
foreach (self::NON_SERIALIZABLE_PROPERTIES as $property) {
107+
unset($object_vars[$property]);
108+
}
109+
110+
return $object_vars;
92111
}
93112

94113
/**

render.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
if ($config->saveConfig) {
7676
$outputHandler->v("Writing the config file", VERBOSE_MESSAGES);
77-
file_put_contents("phd.config.php", "<?php\nreturn " . var_export($config->getAllFiltered(), 1) . ";");
77+
file_put_contents("phd.config.php", "<?php\nreturn " . var_export($config->getAllSerializableProperties(), 1) . ";");
7878
}
7979

8080
if ($config->quit) {

0 commit comments

Comments
 (0)