0

Lets say i have a class Foo with a method printname(), Then i create an alias Bar to the Foo and make the call: Bar::printname(), I want this call to print "Bar" on the screen.

<?php

class Foo {

    function printname () {
        ...
    }
}

class_alias('Foo', 'Bar');

Bar::printname(); // Print "Bar"

In short, i want the class Foo to have a function that prints the name of the alias it's called with, and not the name of the class(Foo).

Thanks :)

areller
  • 4,800
  • 9
  • 29
  • 57
  • [This link](http://stackoverflow.com/questions/9229605/in-php-how-do-you-get-the-called-aliased-class-when-using-class-alias) might help you – Meeuuuhhhh Jun 29 '15 at 13:49

1 Answers1

0

You can't, but I always thought class aliases were a silly idea anyway.

If you really need to alias a class, you could cheat and use inheritance.

class Foo {

    public static function printname() {
        echo get_called_class();
    }
}

class Bar extends Foo { }

Bar::printname(); // Print "Bar"
PiranhaGeorge
  • 999
  • 7
  • 13