473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Get calling class

I have the following:

class A {
function something($args) {
print $CLASS_THAT_IS_CALLING_THIS_FUNCTION;
}
}

class B {
function execute($args) {
$a = new A();
$a->something($args);
}
}

When executing B::execute($args), it should print B. I can't provide
the name of the class on the arguments. I want it, because A is only
supposed to access files from a folder with the name of the class, so
on B, A would access files/B/... On C, A would access files/C/, and so
on. Is there any way of doing this?
Jun 2 '08 #1
2 5497
Bruno Rafael Moreira de Barros wrote:
I have the following:

class A {
function something($args) {
print $CLASS_THAT_IS_CALLING_THIS_FUNCTION;
}
}

class B {
function execute($args) {
$a = new A();
$a->something($args);
}
}

When executing B::execute($args), it should print B. I can't provide
the name of the class on the arguments. I want it, because A is only
supposed to access files from a folder with the name of the class, so
on B, A would access files/B/... On C, A would access files/C/, and so
on. Is there any way of doing this?
i think you could use this:
http://uk3.php.net/debug_backtrace

- andreas
Jun 2 '08 #2
On Apr 21, 11:01 am, Andreas Gustafsson <andr...@dreamticket.com>
wrote:
Bruno Rafael Moreira de Barros wrote:
I have the following:
class A {
function something($args) {
print $CLASS_THAT_IS_CALLING_THIS_FUNCTION;
}
}
class B {
function execute($args) {
$a = new A();
$a->something($args);
}
}
When executing B::execute($args), it should print B. I can't provide
the name of the class on the arguments. I want it, because A is only
supposed to access files from a folder with the name of the class, so
on B, A would access files/B/... On C, A would access files/C/, and so
on. Is there any way of doing this?

i think you could use this:http://uk3.php.net/debug_backtrace

- andreas
I actually thought of using __CLASS__ and I thought it worked, for a
while. But then it didn't. Might have just been my impression.

Using debug_backtrace:

<?php
class A {
function something($args) {
$s = debug_backtrace();
print "views/{$s[1]['class']}/file.phtml";
}

}

class B {
function execute($args) {
$a = new A();
$a->something($args);
}

}

B::execute(2);
?>

This worked perfectly. Unless you have C::somefunction, calling
B::somefunction, which then calls A::somefunction, but that will never
be needed, thankfully. Although a limitation in my scripts is
something I would never like, it's the only way I have of making sure
classes don't open folders that don't belong to them. Just me being
paranoid, once more.
Jun 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jarmopy | last post by:
Hi, I have made a service with C# and calling that service class from another C# program with remoting. (Referendes from the calling program) That service class is configured so that garpage...
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
5
by: Dave Veeneman | last post by:
I'm using inheritance more than I used to, and I find myself calling a lot of base class methods. I generally call a base method from a dreived class like this: this.MyMethod(); I'm finding...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
12
by: Ron | last post by:
Greetings, I am trying to understand the rational for Raising Events instead of just calling a sub. Could someone explain the difference between the following 2 scenarios? Why would I want to...
2
by: sumanthsclsdc | last post by:
Hello friends, I have a problem, I implemented a class which uses tkinter and displays the window as required, the class will create a window with listbox and inserts some items into it, I...
6
by: Anthony Smith | last post by:
I can call a class using "->", but it complains about the :: I see on the net where :: is used. Is there a good explanation on when to use one over the other or the differences? $help = new...
10
by: Finger.Octopus | last post by:
Hello, I have been trying to call the super constructor from my derived class but its not working as expected. See the code: class HTMLMain: def __init__(self): self.text = "<HTML><BODY>";...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: Emile van Sebille | last post by:
mercado mercado wrote: Well, the class name is in __class__ so changing 'print x' to 'print __class__' will show foo in both cases, which is in fact the name of the class which is calling it....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.