Home
Username:
Password:
FileMaker 9 & PHP Foundations Tutorials

PHP Data / Testing Variables & Constants




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

We've talked about the different data types and the use of variables in PHP. Now let's get into specifically trying to test whether or not a specific variable is a value or whether it's a certain data type. We do this in FileMaker Pro most commonly inside our managed database dialog where, for a specific field, we can set validations of a certain data type, such as not empty or unique and so forth. In PHP, we'll have to write the code that tests the value or the type of data ourselves. Inside of the 0403.php file, we have some code remaining, left over from a previous lesson where we described the different data types in PHP. We talked about the scaler data types and then the other more unique or complicated data types. Then we talked about casting the data types. Now let's talk about testing a specific variable for its data type or a specific value. For instance, for a string, we would want to make sure, perhaps, that it indeed was a string. We could say if, and in parentheses, is string, and then in parentheses we'll place the variable A, then execute some block of PHP code. The is string function tests to see whether the variable is of type string. We could also test to make sure that the variable A is set. We could use if is set, and the variable A. Then execute some blocks of PHP code. We also may want to check if A is actually empty. In other words, it does not contain any assigned value. We could say if empty, A. And then execute our PHP code. These are three different specific ways to check to see if the variable A is string or if it contains a value. For a Boolean value, we can check to make sure it's a Boolean by saying if is Bool, and then passing the variable. And then execute PHP code of it returns true. We can also use the if set and is empty test functions for any of these different types of data. We can check our integer values by saying if is int, to make sure that we are indeed receiving an integer value for the variable C. We can do the same thing for float. Notice with all these different variables we can always use if is set and if empty. Another thing we can do for all the different types of variables is we can check to see if they are a null value. I can say if is null, and whatever variable or value that I want to check. Many times I will want to unset a value or a variable. If it's been set, I can say unset and then pass the variable's name. Notice that these are all scaler values. Scaler values are very different from the non-scaler data types. If I want to check if it's a scaler value, I could say if is scaler, and then pass whatever variable it is that I want to test against. Likewise with the rest of our different data types, we can test if they are indeed of that data type. Is array, if is object and for a resource, we can test if is resource and then we've already talked about if is null. These are the different ways that we can test our variables. We can also test the constants in the same way. Another thing that we can do with constants is we can actually see if it was defined. For instance, we may have in our code the constant name and the value lance. Later on in our code, we can verify this by saying if defined, the constant name, then execute some PHP code. So with our constants we can not only check what their value is, but whether or not they've even been defined. These are some very straightforward ways to test your variables and your constants, not only for their values, but also to test whether or not they've ever been assigned, whether they are null, whether they're set or not set, or whether they're empty. And you can also tell whether or not they are the type that you are expecting. In this way you can do stringent data checks and data validation in your PHP code. This concludes our lesson on testing variables and constants.

Tutorial Information

Course: FileMaker 9 & PHP Foundations
Author: Lance Hallberg
SKU: 33786
ISBN: 1-933736-99-2
Release Date: 2007-08-22
Duration: 9.5 hrs / 107 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available