!isset not picking up undefined var from Flash AS3

I’m having a problem with Flash AS3 and PHP 5.3.29 when posting an undefined var from Flash to PHP. If I force the var to be blank ie: varName =“” then the empty() funct picks it up fine but PHP will not pick up the var as undefined. This is very perplexing and I’d like to get to the bottom of it. my PHP:-

if(!isset($_POST['varName']) || empty($_POST['varName'])){
do something
    do something else

empty != !isset.


will make this clearer for you - the field is still there - and therefore it is “set” - ie, the field EXISTS, so isset() returns true. It’s contents are empty (“”), so empty() returns true.

I suspect that when you tell flash to send ‘undefined’ what it actually does is send fieldname = null;. Which again, still EXISTS, but is empty.

Good reply and thanks. I have though along simliar lines. I have used Charles Proxy to understand what Flash is sending and it clearly shows that Flash is sending and undefined var. I did try forece an"undefined" or undefined to see if I could catch that but they both failed.
To pick up on your rely, if the !isset was set to’ true’ then surely the ‘else’ option would fire which it doesn’t appear to be doing so. My else statement actually retun a result set but a reduced version of it. I’m really stumped but I would like to get to the bottom of it.

OK, so your reply got me thinking and although it totally screws up any XML output I might have got in the result set, I echo’d the $_POST var both before and after !isset. The $POST var according to Flash Charles and the echo before the !isset was undefined and not NULL “” or “undefined”, however PHP is seeing it as isset and not !isset… Why? I don’t know but for anyone experiencing the same issue: - my work around is to force the var as “” empty rather than undefined. Its not graceful or ellegant but it works… I’d still love to know why though!

What did the var_dump say was in the post array? (or perhaps more interestingly, what the type of the ‘varName’ field is)

StarLion thanks for being intrigued…not entirely sure what you mean by ‘fieldName’ my varName is nothing more than a variable, its not data froma field or am I barking up the wrong tree??? The var dump gave me string(9) “undefined” which very odd. Is this PHP deciding its a string?? Seems like you were on the right track all along but why this happens is beyond me…

Flash must have sent the literal “undefined”. PHP doesnt interpret that as a special word, it’s just a string of 9 characters.

In order for isset() to be false, the post request must not send the field at all. Otherwise it IS set, even if to an empty value. (In this case, it was set to a 9 character string “undefined”, which is isset() true and empty() false, as it contains data.)

StarLion, thanks for your input and support. Its strange that PHP is seeing it was a string. Flash won’t let you send somthing empty like this

phpMyVar.varName  = ;

It’ll throw an error. It has to be thus

phpMyVar.varName  = varName;

I must confess that I have not tried simply decalring the variable beforehand rather than explicitly setting it as undefined. What happens when you set a var as undefined in PHP itself ? SOrry, not that experienced with PHP and hence the question. However, when I have the time I’m going to test this thoroughly with declared var, “”, undefined, “undefined” etc but for now I’ll just have to stick with the work around… Thanks again

“undefined” is not a term in PHP.
You can set a value to NULL; but then it’s still set, just set to null.
In order for it to not be defined at all (isset = false), in the POST array, the post array must not contain the thing at all.

In other words, instead of

phpMyVar.varName  = ;

it would have to be

if(varName != undefined) {
phpMyVar.varName  = varName;

(I’m assuming thats how Flash IF statements work; i’m not experienced in Flash.)

Interesting, and thanks again for your support

For those hwo are still wondering… After some investigation and assistance from StarLion it appears that there is no way that you can send a var that is not set (!isset) from flash to PHP. According to PHP it will always be set one way or another
My findings: - When myVar is defiend as a number but not given a value

sendVartoPHP.varName = myVar:Number

is seen by PHP as string(3)“NaN”

sendVartoPHP.varName = myVar:int

is seen by PHP as string(1)“0”

sendVartoPHP.varName = myVar:String

is seen by PHP as NULL

sendVartoPHP.varName = myVar

a ‘none typed’ var is seen by PHP as string(9)“undefined”

sendVartoPHP.varName = ""

is seen by PHP as string(0)


not even setting the var to be sent (as above) is seen by PHP as NULL

1 Like

If you use empty() instead of isset() then this one will achieve the same end result.

Felgall, thats exactly what I ended up doing and it works fine. I started off with !isset and then wanted to get to the bottom of it from a Flash to PHP perspective what warrents !isset - clear nothing there is no such thing when it come to Flash-PHP but thanks for yor input…

Just in case anybody else is confused by this, isset returns false if the value is null even though an entry exists.


Use array_key_exists to determine if an array has a given key.