I have two separate classes where one of them is a logging class. I would like to be able to tell which class is calling the log class functions without passing any parameters.
<?php
class Log {
public function general($message) {
// Tell which class/function is calling this function here
$class = get_called_class();
echo 'Your message was: "'.$message.'" from class: "'.$class.'"';
}
}
class foo {
public function log_something() {
$Log = new Log();
$Log->general('Hello, world!');
}
}
$foo = new Foo();
$foo->log_something();
?>
The output I would like is: Your message was "Hello, world!" from class "foo"
However, the message I'm getting is:
Your message was "Hello, world!" from class "Log"
Am I missing something, or doing something wrong?