| From: Tami Williams | Date Sent: 2010-07-31 15:49:42 |
| Subject: lasso 9 how to check if a variable exists | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last Message | |
So, I'm trying to find out if there are any downsides to using this,
for debugging for example, to check if a variable has been defined:
A. [var_keys->find('MyVarName')->Size]
(outputs 0 or >0)
OR
!(Var_Defined: 'MyVarName') ? 'N/A';
(outputs N/A)
to find out IF a var exists INSTEAD of using
B. [var_defined('MyVarName')]
Because B will _create_ the var 'MyVarName' and so on subsequent
reloads the var will exist even if its not been defined anywhere else
in your code,
but A will not _create_ the var, so I think A is a better option for
debugging.
Another option,
C. [if: (var_defined('MyVarName')]
.... do stuff
[/if]
Alternatives? Opinions?
Also, is there a way to find out the value of the var _without_
creating it if it doesn't already exist, without using a conditional?
I believe this is the way with a conditional:
[if(var_defined('MyVarName'))]
exists [$MyVarName]
[else]
not
[/if]
Thanks in advance.
| From: Steve Piercy - Web Site Builder | Date Sent: 2010-07-31 16:05:16 |
| Subject: Re: lasso 9 how to check if a variable exists | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last Message | |
In 9, using the Quick Code in Admin:
https://lassosoft.wiki.zoho.com/Using-Server-Administration.html#Lasso_Quick_Code
var_defined('MyVarName');
$MyVarName;
=>
FAILURE: -9947 The variable MyVarName was not found
My results are different from yours in B. Do you have a
different context of B? Perhaps you mean within a session?
I use C in the ternary form in my code example for sessions.
https://lassosoft.wiki.zoho.com/Debugging-and-Troubleshooting.html#Interpreting_the_Lasso_9_Error_Stack
<p>Session Fruits: [var_defined('fruit')?$fruit]</p>
--steve
On 7/31/10 at 6:49 PM, tami@[Protected] (Tami Williams) pronounced:
>So, I'm trying to find out if there are any downsides to using
>this, for debugging for example, to check if a variable has
>been defined:
>
>
>A. [var_keys->find('MyVarName')->Size]
>(outputs 0 or >0)
>
>OR
>
>!(Var_Defined: 'MyVarName') ? 'N/A';
>(outputs N/A)
>
>to find out IF a var exists INSTEAD of using
>
>
>B. [var_defined('MyVarName')]
>
>
>Because B will _create_ the var 'MyVarName' and so on
>subsequent reloads the var will exist even if its not been
>defined anywhere else in your code,
>
>but A will not _create_ the var, so I think A is a better option for debugging.
>
>Another option,
>
>C. [if: (var_defined('MyVarName')]
>... do stuff
>[/if]
>
>Alternatives? Opinions?
>
>
>Also, is there a way to find out the value of the var _without_
>creating it if it doesn't already exist, without using a conditional?
>
>I believe this is the way with a conditional:
>
>[if(var_defined('MyVarName'))]
>exists [$MyVarName]
>[else]
>not
>[/if]
>
>
>Thanks in advance.
>
>
>
>
>
>
>
>--
>
>
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy Web Site Builder
Soquel, CA
<web@[Protected]> <http://www.StevePiercy.com/>
| From: Tim Taplin | Date Sent: 2010-07-31 19:18:05 |
| Subject: Re: lasso 9 how to check if a variable exists | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last Message | |
On Jul 31, 2010, at 4:49 PM, Tami Williams wrote:
> So, I'm trying to find out if there are any downsides to using this, for debugging for example, to check if a variable has been defined:
>
>
> A. [var_keys->find('MyVarName')->Size]
> (outputs 0 or >0)
>
> OR
>
> !(Var_Defined: 'MyVarName') ? 'N/A';
> (outputs N/A)
>
> to find out IF a var exists INSTEAD of using
>
>
> B. [var_defined('MyVarName')]
>
>
B. Will not create the var. It would create the var if you did something like [var('myvarname')->type] in which case you would receive a null value and future tests in the same thread would show that $myvarname was defined and was of type null until you use it otherwise.
In my opinion B is the more desirable usage but I can only defend that because the purpose of the tag is to determine whether a var is defined or not, I would imagine that it uses some similar function to A to achieve the result.
> Because B will _create_ the var 'MyVarName' and so on subsequent reloads the var will exist even if its not been defined anywhere else in your code,
>
> but A will not _create_ the var, so I think A is a better option for debugging.
>
> Another option,
>
> C. [if: (var_defined('MyVarName')]
> ... do stuff
> [/if]
>
> Alternatives? Opinions?
>
>
> Also, is there a way to find out the value of the var _without_ creating it if it doesn't already exist, without using a conditional?
>
> I believe this is the way with a conditional:
>
> [if(var_defined('MyVarName'))]
> exists [$MyVarName]
> [else]
> not
> [/if]
>
>
> Thanks in advance.