Answer the question
In order to leave comments, you need to log in
How to get default class properties?
How can I get the default properties of a class?
What is the point.
There is a class Handler
, in it the search and launch of the desired class-command takes place. Each command class has a property protected $name
that specifies the name of this command. Actually by name, identification and launch occurs. All command classes inherit one common class Command
with basic methods. There are many of these command classes. And so the question arose, what is the best way to do this kind of search?
class StartCommand extends Command
{
protected $name = 'start';
public function handle()
{
//
}
}
getName
to the parent class Command
and get the value of the property like so:$commands = [
\StartCommand::class
];
$names = [];
foreach($commands as $commandClassName) {
$name[] = (new $commandClassName)->getName();
}
$name[] = $commandClassName::getName();
// или
$name[] = (new $commandClassName::$name;
Answer the question
In order to leave comments, you need to log in
Static method but without creating an object, as is done in your example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question