Page 1 of 1

[SOLVED] Error with library file after upgrade from 3.0.3.9 to 3.0.4.0

Posted: Mon Mar 03, 2025 2:26 am
by Joe1234
After upgrading my library file stopped working. Every page that calls this function all of a sudden stopped working. It's like the library file is no longer registered. All functions being called from this file no longer work. No changes were made except for the version upgrade. I don't know why, and I don't know what info you need to help.

Error:

Code: Select all

[02-Mar-2025 12:32:00 America/New_York] PHP Fatal error:  Uncaught Error: Call to a member function track() on null in /PATH/storage/modification/admin/controller/common/login.php:134
Stack trace:
#0 /PATH/modification/admin/controller/common/login.php(14): ControllerCommonLogin->validate()
#1 /PATH/modification/system/engine/action.php(79): ControllerCommonLogin->index()
#2 /PATH/controller/startup/router.php(26): Action->execute(Object(Registry), Array)
#3 /PATH/storage/modification/system/engine/action.php(79): ControllerStartupRouter->index()
#4 /PATH/storage/modification/system/engine/router.php(77): Action->execute(Object(Registry))
#5 /PATH/storage/modification/system/engine/router.php(66): Router->execute(Object(Action))
#6 /PATH/system/framework.php(179): Router->dispatch(Object(Action), Object(Action))
#7 /PATH/system/startup.php(104): require_once('/PATH/system/framework.php')
#8 /PATH/index.php(19): start('admin')
#9 {main}
  thrown in /PATH/storage/modification/admin/controller/common/login.php on line 134

This is the way the library file is structured:

Code: Select all

<?php
	class Guard {

		private $data = array();
		private $config;
		private $session;
		private $db;
		private $registry;
		private $customer;
		private $htaccess_block;
		//protected $registry;

		public function __construct($registry) {

			$this->registry = $registry;

			$this->config = $registry->get('config');
			$this->db = $registry->get('db');
			$this->request = $registry->get('request');
			$this->session = $registry->get('session');
			$this->log = $registry->get('log');

			$this->customer = $registry->get('customer');

		}

		public function __get($name) {

		   return $this->registry->get($name);

		}
		
		public function track($name, $interaction, $location) {
		
		}
	}
?>
This is the call to the function:

Code: Select all

		$name = $this->request->post['name_al'] ?? "";
		$hi2 = $this->request->post['hi_al'] ?? "";

		$return = $this->Guard->track($name, $hi2, "Data");

Re: Error with library file after upgrade from 3.0.3.9 to 3.0.4.0

Posted: Mon Mar 03, 2025 2:54 am
by Joe1234
I found the issue, I apparently I put "$this->Guard = new Guard($this->registry);" at the top of my function calling to the library file. But now more questions.

1/ Did I miss something in creating my library file? And if not, why was this changed to require me to do this now? Was it a security issue? It was working fine before I don't see how this improves anything by requiring more coding.
2/ Why am I not seeing this error happen with other mods (all mods older than the one I'm making)? I don't see other mods that have library files implementing this at the top of functions that require their library.

Thanks

Re: Error with library file after upgrade from 3.0.3.9 to 3.0.4.0

Posted: Mon Mar 03, 2025 6:26 pm
by ADD Creative
Libraries have to be loaded. The other Libraries are probably loaded and set in the registry‎ in the startup files.

Re: Error with library file after upgrade from 3.0.3.9 to 3.0.4.0

Posted: Mon Mar 03, 2025 6:36 pm
by JNeuhoff
There is no such class named 'Guard' in a standard OpenCart. It looks like you are using a 3rd party extension.
In general, always do a check first with all 3rd party extensions to verify they support your OpenCart version.

Re: Error with library file after upgrade from 3.0.3.9 to 3.0.4.0

Posted: Tue Mar 04, 2025 12:44 am
by Joe1234
@ADD: Do you mean the startup loads it as a part of this code in the system/startup.php

Code: Select all

// Autoloader
if (defined('DIR_STORAGE') && is_file(DIR_STORAGE . 'vendor/autoload.php')) {
	require_once(DIR_STORAGE . 'vendor/autoload.php');
}

function library($class) {
	$file = DIR_SYSTEM . 'library/' . str_replace('\\', '/', strtolower($class)) . '.php';

	if (is_file($file)) {
		include_once(modification($file));

		return true;
	} else {
		return false;
	}
}
Or do you mean I have to hard code it somewhere in the startup? If you mean that code should load it, well, it didn't. And if you mean I have to hard code it, how, and why don't I see any other 3rd party files being loaded there?

@JNeuhoff: That's my extension, I'm trying to understand why this happened.

Re: Error with library file after upgrade from 3.0.3.9 to 3.0.4.0

Posted: Tue Mar 04, 2025 8:06 am
by ADD Creative
No, look in admin/controller/startup/startup.php for examples.

Re: Error with library file after upgrade from 3.0.3.9 to 3.0.4.0

Posted: Wed Mar 05, 2025 5:38 am
by Joe1234
Ahh, I did code it like that to include the loading of my system file in the startup. But on the OC upgrade the search for the code to add my snippet to the stratup.php was broken. Once I fix what to search for it should all be good. Thanks.