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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.