Page 1 of 1
variable varible
Posted: Wed Mar 28, 2007 9:49 pm
by SmokyBarnable
In php is there a way to make a variable undecided?...not true and not false...not null yet defined.
Posted: Wed Mar 28, 2007 9:59 pm
by John Cartwright
A variable has to be something, as in a value or null.
What are you trying to do?
Posted: Wed Mar 28, 2007 10:19 pm
by Christopher
"undecided" ... that's the first time I have heard that one! Excellent!
No, PHP variables are either uninitialized, set or unset. Unset vars are NULL and like uninitialized ones have default values based on context.
Posted: Wed Mar 28, 2007 10:24 pm
by SmokyBarnable
I was pondering a subterfuge function and don't think random will make the grade.
Posted: Thu Mar 29, 2007 12:39 am
by Christopher
So a function that appears to be undecided but is secretly deceiving the program as to what it is truly doing. Now that sounds useful. Can you show us some code? What was I thinking. Functions like that are posted here daily.
Posted: Thu Mar 29, 2007 1:42 am
by dreamscape
Subterfuge? That usually is used in the context of an activity.
Never heard it in the context of data. In its normal context, it means something that misrepresents the true nature of the activity, so I'm not sure where you get "undecided," because it is decided; it's just deceitful. So using that in the context of data the closest thing it seems to me would be scrambling or encryption, for which any cipher should do the trick.
Or, if you actually are looking for "undecided" variables, you do what all languages do for abstract concepts: You give it an actual value that the language can use to interpret as being the concept. Since PHP has no concept of "undecided" variables, you define your own context to interpret as being "undecided" within your application.
Code: Select all
<?php
/**
* Making a new abstract data type 101
*/
// First, we'll make our data type a constant so it is easy to find
define('undecided', 'HELP ME! I do not know what the hell I am!');
// Then we'll make a function similar to the other is_* functions
function is_undecided($var)
{
return ($var === undecided);
}
// Congratulations! You've just made a new abstract data type
// Assign it to a variable like this:
$var = undecided;
// And check it like this:
if (is_undecided($var))
{
see_guidance_counselor();
}
Posted: Thu Mar 29, 2007 8:45 am
by feyd
null is as close to an "undecided" value can get in native types. Why not use it?
Posted: Thu Mar 29, 2007 4:49 pm
by Ambush Commander
Right. If null doesn't work, you can always create a special "Undecided" object to represent the datatype.
Posted: Fri Mar 30, 2007 6:09 am
by Xoligy
But isn't that re-inventing the wheel?
We really need to see what kind of context you're using this for and why you can't use null to provide the best solution.