Does native get_called_class() work for you?
https://secure.php.net/manual/en/function.get-called-class.php
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a function I use to get a calling class:
<?php
namespace App\Helpers;
class DBS
{
public static function __callStatic($method, $params)
{
$class = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['class'];
$slh = strrpos($class, "\") + 1;
$model = "\App\Models\SMVC" . "\" . substr($class, $slh, -10) . "Model";
$instance = new $model();
return $instance->$method(...array_values($params));
}
}
All works good, no problems.
But the question, besides using:
$class = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['class'];
To get the calling class, is there a better way, or is that perfectly alright.
There is nothing to my knowledge besides the backtrace.
I'd pass it as a parameter if it is possible for you.
Please or to participate in this conversation.