From 844516d1f5db555865f1bb7c9836f836392d17ee Mon Sep 17 00:00:00 2001 From: Yahnis Elsts Date: Tue, 10 Jan 2017 13:13:01 +0200 Subject: [PATCH] Treat null entries as non-existent. Add a startsWith() method. This is necessary to avoid fatal errors when trying to retrieve existing but inaccessible properties (i.e. private or protected). --- Puc/v4/Utils.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Puc/v4/Utils.php b/Puc/v4/Utils.php index d4e6693..c36fb83 100644 --- a/Puc/v4/Utils.php +++ b/Puc/v4/Utils.php @@ -24,9 +24,9 @@ if ( !class_exists('Puc_v4_Utils', false) ): $currentValue = $array; $pathExists = true; foreach ($path as $node) { - if ( is_array($currentValue) && array_key_exists($node, $currentValue) ) { + if ( is_array($currentValue) && isset($currentValue[$node]) ) { $currentValue = $currentValue[$node]; - } else if ( is_object($currentValue) && property_exists($currentValue, $node) ) { + } else if ( is_object($currentValue) && isset($currentValue->$node) ) { $currentValue = $currentValue->$node; } else { $pathExists = false; @@ -60,6 +60,18 @@ if ( !class_exists('Puc_v4_Utils', false) ): return $default; } + + /** + * Check if the input string starts with the specified prefix. + * + * @param string $input + * @param string $prefix + * @return bool + */ + public static function startsWith($input, $prefix) { + $length = strlen($prefix); + return (substr($input, 0, $length) === $prefix); + } } endif; \ No newline at end of file