• Home
  • Contact
blog.biernacki.ca

Kuba's Online Workshop

  • Home
  • Contact

Coldfusion and checking if a variable is Defined

01/26/2011 Coldfusion How To PHP Thoughts & Rants 2 Comments

As I work with Coldfusion 9, I can’t help but keep comparing it to PHP, and I get annoyed by some of the small differences.

One thing that I really have been getting annoyed with lately is checking if a variable is defined.  In most cases you could do a simple check, is it empty? However Coldfusion will puke all over itself if you do an isNull() check on a variable that is ‘not defined’. You really have to know the difference it seems between an empty value, vs a variable that has no defined value (to me they are both null/void).

In PHP, this would be a no brainer to check if it was null / empty by doing a simple string comparisson. (Then again PHP doesn’t care if a variable has been defined before you try to use it, which some people hate, but others find very convenient).

Anyway, on to the example…

Example (if our portlet has no value for renderRequest.getRemoteUser() ):

<cfset raw_userid = renderRequest.getRemoteUser() />

<cfif IsNull(raw_userid)>
   It is Null.<br />
</cfif>

The above would simply error out, as you cannot check something that is undefined. Below is the proper way to handle such a scenario with the approach:

<cfset raw_userid = renderRequest.getRemoteUser() />
<cfparam name="raw_userid" default="0">

<cfinvoke component="core.liferay-functions" method="checkIfLogin" returnvariable="userId">
	<cfinvokeargument name="userid" value="#raw_userid#">
</cfinvoke>
cfparamcoldfusionisDefinedisNull()PHP

Really cool 404 page on GitHub

Google adding Chrome Desktop Notification for Gmail

Categories
  • Android
  • Apple
  • Coldfusion
  • Cool Apps
  • CSS
  • GitHub
  • Hardware
  • How To
  • In the News
  • Javascript
  • Linux
  • PHP
  • RC Hobby
  • Reviews
  • SysAdmin
  • Thoughts & Rants
  • Tinkering
Recent Comments
  • Jim on Fixing ONKYO RC-710m Remote volume issues
  • Tony on Fixing ONKYO RC-710m Remote volume issues
  • Robert Lawrence on Fixing ONKYO RC-710m Remote volume issues
  • Dasen on Fixing ONKYO RC-710m Remote volume issues
  • Ahmed on Fixing ONKYO RC-710m Remote volume issues
RollmyBlog
  • Twitter
  • WebMojo Design
  • Windsor Ultimate
Archives
  • June 2020
  • January 2015
  • June 2014
  • February 2014
  • January 2014
  • December 2013
  • May 2013
  • February 2013
  • July 2012
  • June 2012
  • February 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • April 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • August 2010
  • July 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • November 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • June 2008
  • October 2007
  • September 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • January 2007
Proudly powered by WordPress | Theme: Doo by ThemeVS.