Jump to content

OOP \ Calling Class name Question


kickassamd

Recommended Posts

<?php

class aClassName
{
public function register($varName, $varValue)
{
	// In here i would like to get the classes name that called this function.
}
}

class thisWillCallaClassName
{
public function blah()
{
	// I would like to call aClassName->register() from here and set this classes name automatically with no extra parameters to register
}
}
?>

 

Is it possible to have a class that when called from within another class can get the classes name that is calling a function within. IE

 

class people

 

class bob -> calls a method in the people class, and the people class knows it was the class bob who is talking to it.

Link to comment
https://forums.phpfreaks.com/topic/139897-oop-calling-class-name-question/
Share on other sites

not really...you can loop through debug_backtrace(), but that isn't recommended.

 

can you pass the classname or $this as an argument to the register method? if you pass $this, the register method can use get_class() to see what the class is

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.