Skip to content

Commit b61502a

Browse files
committedMar 1, 2024·
Allow no header
1 parent 505401a commit b61502a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed
 

‎src/PHP.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,20 @@ public static function import(string $in): mixed {
3131
return $vars;
3232
}
3333

34-
public static function export(mixed $in): string {
34+
public static function export(mixed $in, bool $noHeader=false): string {
35+
$header = '';
36+
if ($noHeader === false) {
37+
$header = '<?' . 'php' . PHP_EOL . PHP_EOL.
38+
'declare(script_types=1);' . PHP_EOL . PHP_EOL;
39+
}
3540
if (!is_array($in) || Utils::arrayIsList($in)) {
36-
return VarExporter::export($in);
41+
return $header . VarExporter::export($in);
3742
}
3843
$blocks = [];
3944
foreach ($in as $key => $value) {
4045
$blocks []= "\$vars[" . VarExporter::export($key) . "] = ".
4146
VarExporter::export($value) . ";\n";
4247
}
43-
return join("", $blocks);
48+
return $header . join("", $blocks);
4449
}
4550
}

0 commit comments

Comments
 (0)
Please sign in to comment.