Using custom classes

Hey all,

I am trying to use custom classes globally, so i setup a TestClass.php with a public test function() returning a simple string.
Just for testing before i can continue.

For this to work i created a folder with php file in:

The code looks like:

namespace Concrete\Package\FishueelPackage\Src\TestClass;

class TestClass {
	public function test() {
		return "Test";	


And from another file, inside:

I try to get/use the class using:

use \Concrete\Package\FishueelPackage\Src\TestClass\TestClass;

$testVar = TestClass::test();

But everytime i try to use it like the code above i get an error: “HTTP ERROR 500”

I searched the forums and google hoping to find a solution, but without succes.

Could anyone help me out, i thought this would be a bit easier after reading several posts online on stackoverflow.


Rather than living in the Concrete namespace, try setting up your own package specific namespace

See pkgAutoloaderRegistries

Okay, so i am probably misreading something or i dont understand it at all.

As far as i understand, i need to put the following:

protected $pkgAutoloaderRegistries = array(
	'src/TestClass' => '\TestClass'

In the controller.php of the package.

Change the namespace in the folder/class: “packages/fishueel_package/src/TestClass/TestClass.php”
“namespace Concrete\Package\FishueelPackage\Src\TestClass;”

And place the function:

public function on_start()
    $listener = \TestClass();
    $listener->addListeners(); //is this a Concrete function?

In the controller.php of the package as well, however whenever i insert the on_start() function its giving me the error:
“Call to undefined function TestClass()”

And without the on_start() function, i still cant seem to get variables or call the class from another file.

Not quite
No need for the on_start().
The namespace maps to a folder, not to the actual class/file

protected $pkgAutoloaderRegistries = array(
	'src/TestClasses' => '\TestClassses'



Namespace TestClassses;
class MyTestClass {...}

You can create further classes and nest namespaces beneath \TestClasses\ without further declaration.

Thank you very much! Its a little bit clearer now. I got it to work thanks to your help!

1 Like