473,696 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can $this be passed as a method parameter?


In a class, can $this be passed by reference or value?

function setDatabaseObje ct("MySql", $this) {
// some code here checks the name of the
// class of the object that is calling this method
}

For security, and to enforce naming conventions, I'd like for some of
my objects to only be callable from certain classes, but the only way
I can think for an object to get the name of the calling code is if I
had in the $this keyword.

Jul 17 '05 #1
2 1306
On 2005-02-04, lk******@geocit ies.com <lk******@geoci ties.com> wrote:

In a class, can $this be passed by reference or value?

function setDatabaseObje ct("MySql", $this) {
// some code here checks the name of the
// class of the object that is calling this method
}

For security, and to enforce naming conventions, I'd like for some of
my objects to only be callable from certain classes, but the only way
I can think for an object to get the name of the calling code is if I
had in the $this keyword.


in php5 you would mean something like this?

function foo($caller, $bar)
{
// do something with the reflection api i can find in the manual?
}

$class = new Class;
foo($class, "fubar");


--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2
<lk******@geoci ties.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .

In a class, can $this be passed by reference or value?

function setDatabaseObje ct("MySql", $this) {
// some code here checks the name of the
// class of the object that is calling this method
}

For security, and to enforce naming conventions, I'd like for some of
my objects to only be callable from certain classes, but the only way
I can think for an object to get the name of the calling code is if I
had in the $this keyword.


A situation for debug_backtrace (). Just keep stepping back until you find a
class name that's permitted.

http://www.php.net/debug_backtrace/
Jul 17 '05 #3

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

Similar topics

2
3762
by: Marcin | last post by:
Hello! Is there any method to detect parameters values passed to called method? For example: public Guid ApplicationLogin(string userName, string password, int dbId)
8
1166
by: Derrick | last post by:
I saw the ref param keyword relating to base types. Just checking, if I pass an object around to other class constructors, there will only be one instance of the object, correct? Thanks! Derrick
1
1459
by: Jackie W | last post by:
Has .NET any XML-based validation framework or tool classes to validate parameters passed to an Web Service? I need only couple of types validation - is parameter passed to Web Service method empty - does parameter belong to certain value set which is mentioned earlier somewhere in XML files. So, very simple validation. Cheers!
6
4879
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
1
4109
by: kplkumar | last post by:
I am trying to get the method and the parameters passed to that method from the stackTrace. My code is, private void GetExecutingMethodInfo() { StackTrace trace = new StackTrace(false); for (int index = 0; index < trace.FrameCount; ++index)
18
6588
by: Dave Booker | last post by:
I have a Thread making a callback to a Form function that alters Form data. Of course, the debugger is telling me, "Cross-thread operation not valid: Control 'FormTest' accessed from a thread other than the thread it was created on." But I am locking before I touch the shared data, so do I actually need to worry about this, or is it just the debugger being oversimplistic? Specifically, I have:
0
929
by: André | last post by:
Hi, I have still this unsolved problem, so i post it again. I hope someone replies and solves this or tells me it's impossible to do that this way ... My feeling is that it must work ... I have a detailsview for inserting data, and a dropdownlist which selectedValue must be used to fill one of the field of the detailsview. Table 'pc' is related to table 'lok'.
52
3212
by: Julie | last post by:
I'm supporting an application at work. Below are some code segments that I can't understand how they work. First let me say, I would never code this standard. I'm just really creeped out that it works. Here's the setup. I have a function, called GetEmployeeCertifications, that is going to make a call to a SQL DB and return a result set. This module calls another function, called FillParameters, to determine if SQL parameters need to...
83
3936
by: Anonymous | last post by:
Came across some code summarized as follows: char const* MyClass::errToText(int err) const { switch (err) { case 0: return "No error"; case 1: return "Not enough"; case 2: return "Too much"; default: return "Unknown error";
28
1299
by: Mike Hofer | last post by:
I've been maintaining some source code, and I've noticed some radical inconsistency in the code, particularly in the way that parameters are validated. I've noticed that this seems to have been pretty much the case throughout my career. For instance, consider the following block: If siteId <= 0 Then Throw New ArgumentOutOfRangeException("siteId") End If
0
8656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9141
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9005
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8846
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7694
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4605
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1989
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.