473,775 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

__set() TRUE/FALSE

What is the easiest way of testing whether a call to __set() has been
successful?

At the moment doing

$success = ($foo->bar = "fred");
echo $success

returns "fred", even though the __set function returns TRUE.

Any thoughts?
Dec 12 '07 #1
4 1561

"turnitup" <same@samewro te in message
news:47******** *************** @news.zen.co.uk ...
What is the easiest way of testing whether a call to __set() has been
successful?

At the moment doing

$success = ($foo->bar = "fred");
echo $success

returns "fred", even though the __set function returns TRUE.

Any thoughts?
whatever happens to or during $foo->bar being set, you are doing a double
assignment...tw o variables being given the same assignment. 'fred' is NOT
being piped to $success through $foo. further, if bar is a *defined*
interface of $foo, __set() will NEVER be called. __set() is meant to handle
*undefined* interfaces the caller is trying to use...a good place to say,
'invalid property accessed'.
Dec 12 '07 #2
turnitup wrote:
What is the easiest way of testing whether a call to __set() has been
successful?
Give your object a property:

public $successful_set ;

And then have your __set() function set $successful_set to TRUE or FALSE
whenever it is called.

Then after running $foo->bar='fred', you can just check
$foo->successful_set .

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 5 days, 9:58.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
Dec 13 '07 #3
Toby A Inkster wrote:
turnitup wrote:
>What is the easiest way of testing whether a call to __set() has been
successful?

Give your object a property:

public $successful_set ;

And then have your __set() function set $successful_set to TRUE or FALSE
whenever it is called.

Then after running $foo->bar='fred', you can just check
$foo->successful_set .
Good idea! Thinking outside the box. The mark of a creative programmer!
Dec 13 '07 #4

"turnitup" <same@samewro te in message
news:47******** **************@ news.zen.co.uk. ..
Toby A Inkster wrote:
>turnitup wrote:
>>What is the easiest way of testing whether a call to __set() has been
successful?

Give your object a property:

public $successful_set ;

And then have your __set() function set $successful_set to TRUE or FALSE
whenever it is called.

Then after running $foo->bar='fred', you can just check
$foo->successful_set .
Good idea! Thinking outside the box. The mark of a creative programmer!
not to take anything away from toby, but that's pretty standard...not very
out-of-the-box at all. however, toby has them often, so pointing this out is
not to his detriment.
Dec 13 '07 #5

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

Similar topics

3
2552
by: Pingveno | last post by:
I'm writing a web application that requires meta data in some objects. I'm trying to make to API as clean as possible. Would it be better to have something like this: class Mama { public $meta; function __construct(){ $this->meta = new Meta(array of data); } }
46
4261
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
3
2573
by: drs | last post by:
I just upgraded my Python install, and for the first time have True and False rather than 1 and 0. I was playing around at the command line to test how they work (for instance, "if 9:" and "if True:" both lead to the conditional being executed, but True == 9 -> False, that this would be true was not obvious to me -- "True is True" is True, while "9 is True" is false even though 9 evaluates to True.) Anyhow, in doing my tests, I...
35
3397
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
5
5537
by: Jon Maz | last post by:
Hi All, I'm reasonably proficient with C#, and am starting with php5. I was happy to learn of the __get and __set methods, but am encountering a problem using them to set an object property of type "array". Below is a simple example of the problem I'm having with a sample object "Article", which has an array property "authors". As you can see, I can't even use standard php array syntax to set a single author, even though the same...
14
2481
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a "counted" string and data in a binary file. Given... #include <stdio.h> int main(int argc, char *argv) { char bstring;
48
30169
by: Skybuck Flying | last post by:
Hi, I came across this C code which I wanted to understand etc it looked like this: if (-1) etc It made me wonder what the result would be... true or false ? In C and Delphi
30
3160
by: Jason | last post by:
I am fairly new to ASP--I have been using it about 2 months. I did these tests (below), and it doesn't make sense to me. False is equal to 0, and that's fine. True should be equal to 1, but it's not. Actually, True should be equal to anything but False, null, and 0. Is there a workaround for this? Or do I need to change all my comparisons to = 1 instead of = true? response.write True = 1 'prints False response.write True = 0 ...
1
4785
by: Mads Lee Jensen | last post by:
is it the __set() purpose to be called if a property exists in the object but is out of the scope. or is it only to be used for 'undefined instance properties'. test: class Magic_Set { public $fornavn = ''; private $efternavn = '';
0
9622
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...
1
10051
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9916
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
8939
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...
1
7464
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5360
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...
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
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.