From 98d46db7c51cf8e4f8648b383d28db78dd22d055 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 4 Oct 2017 17:03:14 -0500 Subject: [PATCH] Crypt/Base: use eval() instead of create_function() for >= 5.3 --- phpseclib/Crypt/Base.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/phpseclib/Crypt/Base.php b/phpseclib/Crypt/Base.php index 91ebe593..d4d93ba3 100644 --- a/phpseclib/Crypt/Base.php +++ b/phpseclib/Crypt/Base.php @@ -526,8 +526,8 @@ class Crypt_Base $this->_setEngine(); // Determining whether inline crypting can be used by the cipher - if ($this->use_inline_crypt !== false && function_exists('create_function')) { - $this->use_inline_crypt = true; + if ($this->use_inline_crypt !== false) { + $this->use_inline_crypt = version_compare(PHP_VERSION, '5.3.0') || function_exists('create_function'); } } @@ -2550,6 +2550,11 @@ class Crypt_Base } // Create the $inline function and return its name as string. Ready to run! + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { + eval('$func = function ($_action, &$self, $_text) { ' . $init_crypt . 'if ($_action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' } };'); + return $func; + } + return create_function('$_action, &$self, $_text', $init_crypt . 'if ($_action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' }'); }