Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Error with PHP7.3 with LoggerManager.php #7268

Closed
Abuelodelanada opened this issue May 7, 2019 · 1 comment
Closed

Fatal Error with PHP7.3 with LoggerManager.php #7268

Abuelodelanada opened this issue May 7, 2019 · 1 comment
Labels
Area: Environment Issues & PRs related to the application environment Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds Status:Fix Proposed A issue that has a PR related to it that provides a possible resolution Type:Bug Bugs within the core SuiteCRM codebase
Milestone

Comments

@Abuelodelanada
Copy link
Contributor

Issue

When running SuiteCRM 7.10.x with PHP7.3.x the following Fatal error is raised

[Tue May 07 14:47:54.341575 2019] [php7:notice] [pid 24387] [client 127.0.0.1:42204] PHP Fatal error:  Uncaught Error: Using $this when not in object context in /home/jose/trabajos/gca-suitecrm7.10x/include/SugarLogger/LoggerManager.php:169
Stack trace:
#0 /home/jose/trabajos/gca-suitecrm7.10x/custom/include/SugarLogger/SuiteWSLogger.php(83): LoggerManager::setLevel('webservices')
#1 /home/jose/trabajos/gca-suitecrm7.10x/include/SugarLogger/LoggerManager.php(219): SuiteWSLogger->__construct()
#2 /home/jose/trabajos/gca-suitecrm7.10x/include/SugarLogger/LoggerManager.php(88): LoggerManager->_findAvailableLoggers()
#3 /home/jose/trabajos/gca-suitecrm7.10x/include/SugarLogger/LoggerManager.php(180): LoggerManager->__construct()
#4 /home/jose/trabajos/gca-suitecrm7.10x/include/entryPoint.php(156): LoggerManager::getLogger()
#5 /home/jose/trabajos/gca-suitecrm7.10x/index.php(48): require_once('/home/jose/trab...')
#6 {main}
  thrown in /home/jose/trabajos/gca-suitecrm7.10x/include/SugarLogger/LoggerManager.php on line 169, referer: http://localhost/gca-suitecrm7.10x/index.php?module=Home&action=index

In include/SugarLogger/LoggerManager.php line 169 we have:

public function setLevel(
    $name
    ) {
    if (isset(self::$_levelMapping[$name])) {
        $this->_level = $name;
    }
}

We should use:

self::$_level = $name;

instead of:

$this->_level = $name;

Expected Behavior

Not having a Fatal error using PHP 7.3.x, the current stable version

Actual Behavior

A Fatal error is raised

Possible Fix

modified   include/SugarLogger/LoggerManager.php
@@ -48,7 +48,7 @@ if (!defined('sugarEntry') || !sugarEntry) {
 class LoggerManager
 {
     //this the the current log level
-    private $_level = 'fatal';
+    private static $_level = 'fatal';
 
     //this is a list of different loggers that have been loaded
     protected static $_loggers = array();
@@ -79,7 +79,7 @@ class LoggerManager
     //only let the getLogger instantiate this object
     private function __construct()
     {
-        $level = SugarConfig::getInstance()->get('logger.level', $this->_level);
+        $level = SugarConfig::getInstance()->get('logger.level', self::$_level);
         if (!empty($level)) {
             $this->setLevel($level);
         }
@@ -100,14 +100,14 @@ class LoggerManager
         $message
         ) {
         if (!isset(self::$_levelMapping[$method])) {
-            $method = $this->_level;
+            $method = self::$_level;
         }
         //if the method is a direct match to our level let's let it through this allows for custom levels
-        if ($method == $this->_level
+        if ($method == self::$_level
                 //otherwise if we have a level mapping for the method and that level is less than or equal to the current level let's let it log
                 || (!empty(self::$_levelMapping[$method])
                     && (
-                            (isset(self::$_levelMapping[$this->_level]) ? self::$_levelMapping[$this->_level] : null) >=
+                            (isset(self::$_levelMapping[self::$_level]) ? self::$_levelMapping[self::$_level] : null) >=
                             (isset(self::$_levelMapping[$method]) ? self::$_levelMapping[$method] : null)
                     ))) {
             //now we get the logger type this allows for having a file logger an email logger, a firebug logger or any other logger you wish you can set different levels to log differently
@@ -130,12 +130,12 @@ class LoggerManager
     public function wouldLog($method)
     {
         if (!isset(self::$_levelMapping[$method])) {
-            $method = $this->_level;
+            $method = self::$_level;
         }
-        if ($method == $this->_level
+        if ($method == self::$_level
                 //otherwise if we have a level mapping for the method and that level is less than or equal to the current level let's let it log
                 || (!empty(self::$_levelMapping[$method])
-                        && self::$_levelMapping[$this->_level] >= self::$_levelMapping[$method])) {
+                        && self::$_levelMapping[self::$_level] >= self::$_levelMapping[$method])) {
             return true;
         }
         return false;
@@ -166,7 +166,7 @@ class LoggerManager
         $name
         ) {
         if (isset(self::$_levelMapping[$name])) {
-            $this->_level = $name;
+            self::$_level = $name;
         }
     }

Steps to Reproduce

  1. Run SuiteCRM 7.10.x in PHP 7.3.x
  2. Verify Fatal error in PHP log.

Your Environment

  • SuiteCRM Version used: 7.10.x
  • Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Firefox 66.0.3
  • Environment name and version (e.g. MySQL, PHP 7): PHP 7.3.5
  • Operating System and version (e.g Ubuntu 16.04): Ubuntu 19.04
@Dillon-Brown Dillon-Brown added Type:Bug Bugs within the core SuiteCRM codebase Area: Environment Issues & PRs related to the application environment Status:Fix Proposed A issue that has a PR related to it that provides a possible resolution Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds labels May 8, 2019
Abuelodelanada added a commit to gcoop-libre/SuiteCRM that referenced this issue May 9, 2019
@Mausino
Copy link
Contributor

Mausino commented May 9, 2019

@Dillon-Brown should be this issue marked by some milestone? because we haven't any yet active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Environment Issues & PRs related to the application environment Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds Status:Fix Proposed A issue that has a PR related to it that provides a possible resolution Type:Bug Bugs within the core SuiteCRM codebase
Projects
None yet
Development

No branches or pull requests

4 participants