ColdFusion 9 New Features
Illustration by Don Barnett

ColdFusion 9 New Features

with Daniel Short

Video: Working with LOCAL scope in functions

Dealing with variable encapsulation and objects and methods is always a lot of trouble. Making sure that you make all of your methods thread-safe by keeping their variables all tucked inside nice and neat can be laborious. And it's all too easy to miss a var keyword in front of a variable to keep it local to the function. ColdFusion 9 introduces a new scope. The LOCAL scope, that is confined to a specific method or function, making it much easier to make sure you don't accidentally leak variables outside of your functions. To demonstrate this in the Chapter4 folder, open localscope.cfm.
Expand all | Collapse all
  1. 4m 30s
    1. Welcome
      53s
    2. Using the exercise files
      3m 37s
  2. 7m 49s
    1. Adding managing and comparing servers
      5m 26s
    2. Monitoring server health
      2m 23s
  3. 22m 10s
    1. Setting the default data source and SMTP
      5m 6s
    2. Getting programmatic debugging and exception handling
      5m 54s
    3. Reviewing the new onCFCRequest method
      5m 29s
    4. Using ApplicationStop()
      2m 24s
    5. Working with Server.cfc and onServerStart
      3m 17s
  4. 17m 45s
    1. Using ternary and chained operations
      5m 46s
    2. Using New and Import
      4m 2s
    3. Reviewing CFScript enhancements
      7m 57s
  5. 20m 23s
    1. Building with implicit getters and setters
      4m 26s
    2. Working with LOCAL scope in functions
      4m 35s
    3. Serializing objects
      6m 6s
    4. Writing components in CFScript
      5m 16s
  6. 19m 27s
    1. Getting started with ORM
      5m 51s
    2. Logging ORM activity
      2m 13s
    3. Saving objects to the database
      6m 10s
    4. Defining table relationships
      5m 13s
  7. 16m 59s
    1. Caching page fragments
      5m 29s
    2. Managing the cache
      4m 48s
    3. Working with in-memory files using VFS (RAM disks)
      6m 42s
  8. 12m 39s
    1. Working with Excel spreadsheets
      4m 56s
    2. Working with Word documents
      4m 4s
    3. Working with PowerPoint presentations
      3m 39s
  9. 28m 59s
    1. Loading Google maps with markers onto a page
      4m 53s
    2. Adding a Flash movie with the built-in FLV player
      2m 14s
    3. Using multi-file upload control
      6m 7s
    4. Building a progress indicator
      3m 37s
    5. Working with accordion layouts
      3m 19s
    6. Showing information with data grid enhancements
      5m 1s
    7. Informing users with Confirm Alert and Prompt dialog boxes
      3m 48s
  10. 9m 8s
    1. Accessing IMAP accounts
      6m 31s
    2. Working with the new array functions
      2m 37s
  11. 15s
    1. Goodbye
      15s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course ColdFusion 9 New Features
2h 40m Intermediate Oct 05, 2009

Viewers: in countries Watching now:

In ColdFusion 9 New Features, author and developer Dan Short has gathered together the important updates and improvements in this dynamic web application. Dan showcases the new ColdFusion Builder application throughout the course, using it to work through the new language and CFScript enhancements in this release. He shows how to use the new Server Manager to compare servers and create server groups, as well as monitor server health through notifications. He also explains the new integration with Office applications, building Excel, Word, and even PowerPoint files on the fly from ColdFusion. Finally, he covers the important new Object Relational Mapping feature and how to use the built-in Flash Player. Exercise files accompany this course.

Topics include:
  • Using new implicit Getters and Setters in ColdFusion Builder
  • Utilizing RAM disks using VFS
  • Managing the system cache to boost site/application performance
  • Learning the new ternary and chained operations
  • Loading detailed Google maps with markers and notations onto a web page
Subjects:
Developer Web
Software:
ColdFusion
Author:
Daniel Short

Working with LOCAL scope in functions

Dealing with variable encapsulation and objects and methods is always a lot of trouble. Making sure that you make all of your methods thread-safe by keeping their variables all tucked inside nice and neat can be laborious. And it's all too easy to miss a var keyword in front of a variable to keep it local to the function. ColdFusion 9 introduces a new scope. The LOCAL scope, that is confined to a specific method or function, making it much easier to make sure you don't accidentally leak variables outside of your functions. To demonstrate this in the Chapter4 folder, open localscope.cfm.

In here, I have a function written for you already that shows you all the different ways you can get variables into the LOCAL scope and when variables will not be in the LOCAL scope. So I'm just going to run through this function real quick and then we will view it in the preview and see how the dump shows where variables are getting assigned. So, in the testFunction, in these first two variable declarations you can see that the first one says cfset LOCAL.FirstName, and the second one says cfset var LastName.

The first thing you should be thinking if you have used the var keyword even once is that this is function is going to through an error because all variables with the var keyword have to be at the beginning of the function. In ColdFusion 9 that's changed. You can put a var statement on any variable that you want, anywhere in the function. And it will automatically assign that particular variable through the LOCAL scope. So, again these first two lines have either explicitly declared the LOCAL scope, or used the var keyword in order to force these variables to be inside the LOCAL scope.

Once a variable has been declared in the LOCAL scope, then if you set that value without referencing the scope, it will assume that it's in that LOCAL scope. So, in this case, these reset the values in the LOCAL scope. Even though I don't have the scope defined on the front. Now, down here where I am setting City and State, because these haven't been previously var-ed, they haven't been declared in the LOCAL scope. They are going to be put inside the global variables scope, which is available outside of the function.

So, let's take a look at this in our preview and see exactly what happens. In Safari, I can see my LOCAL scope dump inside of the function and you can see that LOCAL also includes arguments. So if I do LOCAL.arguments. testargument, I would get Dan. The same as if I just did arguments.testargument. Here we can see Terrence and Ryan as the FIRSTNAME and LASTNAME and inside our LOCAL scope. Then I have just dumped the variable scope inside the function and the variable scope outside the function.

And I have limited them to just to show these specific keys so we don't have a whole bunch of garbage to display. So, if I go back to my source code, and change the City and State to have the var in front of them, you can now see that they have been moved into the LOCAL s cope, and are not available outside the function. My other option is to just to prefix them with LOCAL. So, I will do that for both City and State, preview the file again, and you can see it has the exact same effect.

The City and the State are now inside of the LOCAL scope. If you're like me, you've made a habit of defining a local structure in order to keep your variables inside the function. So almost all of my methods and functions start like this. I've always created a LOCAL scope in order to be able to just use variables willy-nilly without having to worry about always varing every single thing. So, if I go and save this and preview again, it has no effect whatsoever on the actual functionality of the page.

ColdFusion is smart enough to know that I'm just really carrying a LOCAL scope and it will ignore that statement. So that's all there is to the LOCAL scope. You still need to make sure that you var all of your variables if you're not going to use the explicit LOCAL scope notation. If you are like me and you have already made a habit of creating a LOCAL scope in your functions and methods, this is going to really change from the way you have always worked. The biggest takeaway is that you can now var your variables anyplace you want. And in fact with the new chained operators that I talked about in an earlier video, you can even var all of your variables in one fell swoop.

So for example, I can, cfset var Firstname = Lastname = empty string. And I can var all my variables in one shot.

There are currently no FAQs about ColdFusion 9 New Features.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed ColdFusion 9 New Features.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.