diff --git a/composer.json b/composer.json
index d9e8c9abee878e082fe3c040fbbff259ca8be58b..1f7dd335e24fcfe10a426b2e4f160d3698c4ec7a 100644
--- a/composer.json
+++ b/composer.json
@@ -56,6 +56,7 @@
         "symfony/http-foundation": "^4.0",
         "symfony/http-kernel": "^4.0",
         "symfony/routing": "^4.0",
+        "symfony/var-exporter": "^5.0",
         "symfony/yaml": "^4.0",
         "twig/twig": "~2.0",
         "webmozart/assert": "~1.7"
diff --git a/composer.lock b/composer.lock
index b7d177b670473c616528b6e6b271715dedfc5a2d..d2e00fd57111b7efcf9674302b1302ee8a1db951 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": "1a322d0137e97d1981af0ddfbe325e75",
+    "content-hash": "4792f2e7d2ff0cd7cb7bb6e70868bfe4",
     "packages": [
         {
             "name": "gettext/gettext",
diff --git a/modules/admin/lib/Controller/Federation.php b/modules/admin/lib/Controller/Federation.php
index 7ba872b7d2fa7cdc6c7550c0ab130d3ce4a297cd..3c5e730f91ba5366dc1e4f6587ef78094b5cd3df 100644
--- a/modules/admin/lib/Controller/Federation.php
+++ b/modules/admin/lib/Controller/Federation.php
@@ -22,6 +22,7 @@ use SimpleSAML\XHTML\Template;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpFoundation\ResponseHeaderBag;
+use Symfony\Component\VarExporter\VarExporter;
 
 /**
  * Controller class for the admin module.
@@ -266,7 +267,7 @@ class Federation
                 unset($entity['metadata_array']['keys']);
             }
 
-            $entities[$index]['metadata_array'] = var_export($entity['metadata_array'], true);
+            $entities[$index]['metadata_array'] = VarExporter::export($entity['metadata_array']);
         }
 
         return $entities;
@@ -328,7 +329,7 @@ class Federation
                 'url' => $source->getMetadataURL(),
                 'name' => $name,
                 'metadata' => $xml,
-                'metadata_array' => var_export($metadata, true),
+                'metadata_array' => VarExporter::export($metadata),
                 'certificates' => $certificates,
             ];
         }
@@ -383,7 +384,7 @@ class Federation
                     unset($entityMetadata['entityDescriptor']);
 
                     $text .= '$metadata[' . var_export($entityId, true) . '] = '
-                        . var_export($entityMetadata, true) . ";\n";
+                        . VarExporter::export($entityMetadata) . ";\n";
                 }
                 $entities = $text;
             }
@@ -465,7 +466,7 @@ class Federation
 
         $t = new Template($this->config, 'admin:show_metadata.twig');
         $t->data['entityid'] = $entityId;
-        $t->data['metadata'] = var_export($metadata, true);
+        $t->data['metadata'] = VarExporter::export($metadata);
         return $t;
     }
 }
diff --git a/modules/saml/www/sp/metadata.php b/modules/saml/www/sp/metadata.php
index c2e58ee43f21fa35d55d448651444d768c682c1d..c5727f0a943f169e401bf7a322882f665deb7ea3 100644
--- a/modules/saml/www/sp/metadata.php
+++ b/modules/saml/www/sp/metadata.php
@@ -1,5 +1,7 @@
 <?php
 
+use Symfony\Component\VarExporter\VarExporter;
+
 if (!array_key_exists('PATH_INFO', $_SERVER)) {
     throw new \SimpleSAML\Error\BadRequest('Missing authentication source id in metadata URL');
 }
@@ -279,7 +281,7 @@ if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] == 'xhtml') {
     $t->data['headerString'] = \SimpleSAML\Locale\Translate::noop('metadata_saml20-sp');
     $t->data['metadata'] = htmlspecialchars($xml);
     $t->data['metadataflat'] = '$metadata[' . var_export($entityId, true)
-        . '] = ' . var_export($metaArray20, true) . ';';
+        . '] = ' . VarExporter::export($metaArray20) . ';';
     $t->data['metaurl'] = $source->getMetadataURL();
     $t->send();
 } else {
diff --git a/www/admin/metadata-converter.php b/www/admin/metadata-converter.php
index f9d0ffd914ceb28971ab5560440f8090064bd872..e85446026ffe914c25819be179571364fc2e0370 100644
--- a/www/admin/metadata-converter.php
+++ b/www/admin/metadata-converter.php
@@ -2,6 +2,8 @@
 
 require_once('../_include.php');
 
+use Symfony\Component\VarExporter\VarExporter;
+
 // make sure that the user has admin access rights
 \SimpleSAML\Utils\Auth::requireAdmin();
 
@@ -40,7 +42,7 @@ if (!empty($xmldata)) {
             unset($entityMetadata['entityDescriptor']);
 
             $text .= '$metadata[' . var_export($entityId, true) . '] = ' .
-                var_export($entityMetadata, true) . ";\n";
+                VarExporter::export($entityMetadata) . ";\n";
         }
         $entities = $text;
     }
diff --git a/www/saml2/idp/metadata.php b/www/saml2/idp/metadata.php
index 1c7983a6371bbf6f56d8e598e81309b79d6aa6c6..cdfa430f17db1489e14c2fdcd8fd1604d815aac6 100644
--- a/www/saml2/idp/metadata.php
+++ b/www/saml2/idp/metadata.php
@@ -2,6 +2,8 @@
 
 require_once('../../_include.php');
 
+use Symfony\Component\VarExporter\VarExporter;
+
 use SAML2\Constants;
 use SimpleSAML\Module;
 use SimpleSAML\Utils\Auth as Auth;
@@ -210,7 +212,7 @@ try {
 
     $metaxml = $metaBuilder->getEntityDescriptorText();
 
-    $metaflat = '$metadata[' . var_export($idpentityid, true) . '] = ' . var_export($metaArray, true) . ';';
+    $metaflat = '$metadata[' . var_export($idpentityid, true) . '] = ' . VarExporter::export($metaArray) . ';';
 
     // sign the metadata if enabled
     $metaxml = \SimpleSAML\Metadata\Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');