473,397 Members | 2,033 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,397 software developers and data experts.

How to intercept calls to the variable?

Expand|Select|Wrap|Line Numbers
  1. class Test {
  2.   public $var1 = 0;
  3.  
  4.   private function simple() {
  5.     // smth
  6.   }
  7. }
  8.  
  9. $obj = new Test;
  10. $obj->var1 = 1;
  11.  
I want a change of variable var1 immediately fulfilled the function simple. How to do it?
Oct 28 '10 #1
1 2129
dlite922
1,584 Expert 1GB
That is not possible to do. You can't have a listener or trigger in a class (Disclaimer: that I know of with basic implementation of OOP).

You can just use a Setter method and call that instead of changing the variable.

Expand|Select|Wrap|Line Numbers
  1.  
  2. public function setVar($newVal)
  3. {
  4.    $this->var1 = $newVal; 
  5.    $this->simple(); 
  6. }
  7.  
  8. }// end class
  9.  
  10. $obj = new Test; 
  11. $obj->setVar(1); 
  12.  
  13.  
You should try to have accessors and setters for all your members. Google Encapsulation.


Dan
Oct 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Matt Leslie | last post by:
I want to write a package to simulate a distributed system with objects at various locations interacting with each other. What I'd like to do is simulate network delays between distant objects...
18
by: Joe | last post by:
Hi, I am trying to alter the refresh rate of an online webpage in a webbrowser control using MFC. However the Timer ID is stored in a local variable and I don't know how to access it. Is there a...
8
by: Peter Olcott | last post by:
Is there any way to intercept system calls to windows such as TextOut and DrawText? what kinds of system calls can be intercepted, and what is the mechanism to accomplish this?
0
by: Joerg Schoen | last post by:
Hi folks! "JSCPP" is a ANSI-C preprocessor and language parser. It can analyze or instrument C-code. The most prominent application currently is to add function trace calls to existing C...
6
by: Valery Polyakov | last post by:
I am drawing lines with a semi-transparent color (alpha=100). When these lines intercept, the color becomes more intense. Is there a way to avoid this, so that I would get the same intensity of...
3
by: Jim Hubbard | last post by:
Is there a way to intercept all GDI calls to the screen in VB.Net? Looking for a remote viewing solution....
9
by: tai | last post by:
Hi. I'm looking for a way to define a function that's only effective inside specified function. Featurewise, here's what I want to do: bar_plugin_func = function() { ...; setTimeout(...);...
2
by: Microsoft Newsserver | last post by:
Hi, I am using VS2005/.Ajax 1.1 . I need to mask the screen during async calls back to the server. I can do this by surrounding the whole screen with a filtered div to prevent click throughs to...
8
by: K Viltersten | last post by:
I've seen some people calling a stored procedure on MS SQL Server and intercepting an invalid parameter list by a switch statement, demanding that each of the parameters names is exactly as the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.