From ed76d125003b7660ca507618b49c2f3d4532e658 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20Pe=CC=81rez?= <jaime.perez@uninett.no>
Date: Mon, 3 Oct 2016 16:08:44 +0200
Subject: [PATCH] Take advantage of ParseError in PHP 7.

When we try to load a configuration file and there's a syntax error, PHP 7 will throw the new ParseError. We can take advantage of that to capture it and give the user a meaningful message back.

This resolves #483.
---
 lib/SimpleSAML/Configuration.php | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php
index 544728fd2..4370473b6 100644
--- a/lib/SimpleSAML/Configuration.php
+++ b/lib/SimpleSAML/Configuration.php
@@ -120,7 +120,17 @@ class SimpleSAML_Configuration
 
             // the file initializes a variable named '$config'
             ob_start();
-            require($filename);
+            if (interface_exists('Throwable')) {
+                try {
+                    require($filename);
+                } catch (ParseError $e) {
+                    self::$loadedConfigs[$filename] = self::loadFromArray(array(), '[ARRAY]', 'simplesaml');
+                    throw new SimpleSAML\Error\ConfigurationError($e->getMessage(), $filename, array());
+                }
+            } else {
+                require($filename);
+            }
+
             $spurious_output = ob_get_length() > 0;
             ob_end_clean();
 
-- 
GitLab