سؤال

I have class Mercedes and it has parent Car and Car has parent Main.
I want to get all parents from Mercedes Class

Mercedes extends Car 
Car extends Main

output should be something like this mercedes<-Car<-Main

هل كانت مفيدة؟

المحلول

This would do:

function GetAllParents(instance) {
   return get_class(instance) . '<-' .
          implode('<-', array_reverse(class_parents(instance)));
}

Outputs all in the right order:

Mercedes<-Car<-Main

See documentation:

نصائح أخرى

try

print_r(class_parents(new Mercedes ));

For more :- http://www.php.net/manual/en/function.class-parents.php

or http://www.php.net/manual/en/function.get-parent-class.php

it will output you as array so need to use implode()

<?php echo implode('<-', class_parents(new Mercedes)); ?>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top