variable varible

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

variable varible

Post by SmokyBarnable »

In php is there a way to make a variable undecided?...not true and not false...not null yet defined.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

A variable has to be something, as in a value or null.

What are you trying to do?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post by SmokyBarnable »

I was pondering a subterfuge function and don't think random will make the grade.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
dreamscape
Forum Commoner
Posts: 87
Joined: Wed Jun 08, 2005 10:06 am
Contact:

Post 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();
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

null is as close to an "undecided" value can get in native types. Why not use it?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Right. If null doesn't work, you can always create a special "Undecided" object to represent the datatype.
Xoligy
Forum Commoner
Posts: 53
Joined: Sun Mar 04, 2007 5:35 am

Post 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.
Post Reply