By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

__set() TRUE/FALSE

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a

"turnitup" <same@samewrote 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...two 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

P: n/a
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

P: n/a
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

P: n/a

"turnitup" <same@samewrote 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 discussion thread is closed

Replies have been disabled for this discussion.