Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Chatwee Posted May 9, 2017 Posted May 9, 2017 Hello everybody, I am currently working on a plugin and having a hard time including my custom library in one of the hooks. Let's say I have a class defined in a class1.php file (location: \[IPS root path]\plugins\myExamplePlugin\lib\class1.php). Here's what the class1.php file looks like: <?php class Example_class { private static $_someValue = null; private static $_anotherValue = null; public static function setSomeValue($someValue) { self::$_someValue = $someValue; } public static function setAnotherValue($anotherValue) { self::$_anotherValue = $anotherValue; } public static function getSomeValue() { return self::$_someValue; } public static function getAnotherValue() { return self::$_anotherValue; } public static function areBothTheValuesSet() { return self::$_someValue !== null && self::$_anotherValue !== null; } } Now, I'd like to use the above class in one of my hooks: hook1.php (location: \[IPS root path]\plugins\myExamplePlugin\hooks\hook1.php. Here's what the hook1.php file looks like: //<?php /* To prevent PHP errors (extending class does not exist) revealing path */ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) ) { exit; } require_once \IPS\ROOT_PATH . "\plugins\myExamplePlugin\lib\class1.php"; class hook1 extends _HOOK_CLASS_ { public function authenticate() { $someValue = \IPS\Settings::i()->someValue; $anotherValue = \IPS\Settings::i()->anotherValue; Example_class::setSomeValue($someValue); Example_class::setAnotherValue($anotherValue); /* irrelevant stuff */ return call_user_func_array( 'parent::authenticate', func_get_args() ); } } And the error I have been getting after the authentication is: Whoops \ Exception \ ErrorException (E_ERROR) Class 'IPS\Example_class' not found Can you guys help me out with this?
Daniel F Posted May 9, 2017 Posted May 9, 2017 You have to replace Example_class::setSomeValue($someValue); Example_class::setAnotherValue($anotherValue); with \Example_class::setSomeValue($someValue); \Example_class::setAnotherValue($anotherValue); since Example_class isn't in the IPS namespace
Recommended Posts
Archived
This topic is now archived and is closed to further replies.