Post by Joe1234 » Mon Mar 03, 2025 2:26 am

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");
Last edited by Joe1234 on Wed Mar 05, 2025 5:39 am, edited 1 time in total.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by Joe1234 » Mon Mar 03, 2025 2:54 am

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

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Mon Mar 03, 2025 6:26 pm

Libraries have to be loaded. The other Libraries are probably loaded and set in the registry‎ in the startup files.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by JNeuhoff » Mon Mar 03, 2025 6:36 pm

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.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Joe1234 » Tue Mar 04, 2025 12:44 am

@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.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Tue Mar 04, 2025 8:06 am

No, look in admin/controller/startup/startup.php for examples.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Joe1234 » Wed Mar 05, 2025 5:38 am

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.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am
Who is online

Users browsing this forum: No registered users and 15 guests