IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesASP Classic  Print This     

Variables (ASP Classic and PHP Cross Reference Guide)

By Mike Prestwood

ASP Classic versus PHP: A side by side comparison between ASP Classic and PHP.

 
Language Basics
 

Language basics is kind of a catch all for absolute beginner stuff. The items (common names) I chose for language basics is a bit random and include items like case sensitivity, commenting, declaring variables, etc.

Variables

[Other Languages] 

Languages Focus

A variable holds a value that you can use and change throughout your code so long as the variable is within scope. With variable declaration, you not only want to know the syntax of how you declare a variable but you also want to know where. Are you allowed to declare a variable inline? What are the available scopes: local vs. global. Can you assign a value at the same time you declare a variable?

ASP Classic:   Dim x

ASP Classic is a loosely typed language. No variable types in ASP (all variables are variants). Declaring variables is even optional unless you use the Option Explicit statement to force explicit declaration of all variables with Dim in that script. Using Option Explicit is strongly recommended to avoid incorrectly typing an existing variable and to avoid any confusion about variable scope.

For example, at the top of my common include file, I have the following:

<%@LANGUAGE=VBScript%>
<%
Option Explicit
'...more code here.
%>
Syntax Example:
Dim Fullname
Dim Age
Dim Weight
 
FullName = "Mike Prestwood"
Age = 32
Weight = 154.4
 
'Declaritive assignment not supported:
''Dim Married = "Y"   '>>>Not supported.
PHP:   $x = 0;

PHP is a loosely typed language. No variable types in PHP. Declaring and using variables are a bit different than in other languages. In PHP, you identify and use a variable with a $ even within strings!

You assign by reference with & as in &$MyVar.

Syntax Example:
$fullname = 'Mike Prestwood';
$FullName = 'Wes Peterson'; //This is a different variable!
$Age = 38;
$Weight = 162.4;
 

echo "Your name is $fullname.
";
echo "You are $Age and weigh $Weight.
";












Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]