Python/Applescript cross reference.
Command | ASP3 (VBScript 5.6) | PHP | Javascript (ECMAscript) | MS SQL (2000+) |
---|---|---|---|---|
General syntax | ||||
Comments, inline | 'my dog has fleas | //my dog has fleas | // comment | -- comment |
Comments, block | Not available Small workaround: If 2 == 1 Then .. do stuff End If ("do stuff" must contain valid code.) |
/* The quick brown fox jumped over the lazy dogs. */ |
/* lines of code */ | /* lines of code */ |
Command termination | None | ; | ; | None |
Quotes | " | " or ' | ' | ' |
Escaping quotes |
"""var text1=""<img src=\""blank.gif\"">"";"
|
\" or use ' to quote and just " to write | \' | '' |
Multiple commands per line | Separate with : | Allowed | Allowed | ? |
Screen output | Response.Write("hello") | echo "hello"; | document.write('hello'); | PRINT 'hello' |
Newline characters |
vbCrLf, outside quotes
Response.Write("hello" & vbCrLf)
|
"\n", inside quotes (must be inside "", not '')
echo "hello \n";
|
? | ? |
Equality test | 2 = 3 2 = 2, 2 <> 3 |
2 == 32 = 2, 2 != 3 |
2 == 3 | 2 = 3 |
Case sensitivity | Everything is case insensitive | Variables case sensitive, functions and commands insensitive | Everything is case sensitive | Everything is case insensitive |
Variable names |
Case insensitive, so strName is the same as STRNAME |
Case sensitive AND must begin with $ so $fName is NOT the same as $FNAME |
Case sensitive | Case insensitive AND must begin with @ |
Usual naming convention variables |
Hungarian notation
strName, intZipCode
|
? |
Camel case
thisIsVariable
|
Pascal Casing
@Name
|
Usual naming convention functions |
Pascal Casing
MyFunction
|
? |
Camel case
myFunction
|
Pascal Casing
MyFunction
|
Unsorted (Class, session) | ||||
Class delimiter | . | -> | ? | ? |
Function kald | Call Test(var1, var2) Function(var1, var2) 'Alle funktionens parametre skal stå i kaldet |
? | ? | ? |
Function kald fra samme class | Call Test() | $this->test | ? | ? |
Function kald fra anden class | Call Regular.Test() | $regular->test | ? | ? |
Session | Session("name") | $_SESSION["name"] | ? | |
Other | ||||
Include outside code |
<!--#include virtual="/filename.inc"--> <!--#include file="/filename.inc"--> <script language="vbscript" runat="server" src="/filename.inc"<>/script> |
? | document.write("<SCR" + "IPT language=\"Javascript\" src=\"filename.js\"><SCRIPT>"); | ? |
Execute inside code |
Server.Execute("filename.inc") Server.Transfer("filename.inc") |
require, require_once, include, include_once (include will only include the file if the line it's in actually executes, and will continue on errors) | ? | ? |
Control Structures | ||||
If statements |
if x=100 then x=x+5 elseif x<200 then x=x+2 else x=x+1 end ifIf (1 = 1) Or (2 = 2) Then If (1 = 1) And (2 = 2) Then If (1 = 2) And (function()) Then (function bliver eksekveret, selvom det er overflødigt, da sætningen aldrig bliver sand) |
if ($x==100) { $x=$x+5; } else if ($x<200) { $x=$x+2; } else { $x++; }if (1 == 1 || 2 == 2) if (1 == 1 && 2 == 2) if (1 == 2 && function()) (function bliver ikke eksekveret, da det er overflødigt, da sætningen aldrig bliver sand) |
||
For loops |
for x=0 to 100 step 2 if x>p then exit for next |
for ($x=0; $x<=100; $x+=2) { if ($x>$p) {break;} } |
||
While loops |
do while x<100 x=x+1 if x>p then exit do loop |
while ($x<100) { $x++; if ($x>$p) {break;} } |
||
Branching |
select case chartName case "TopSales" theTitle="Best Sellers" theClass="S" case "TopSingles" theTitle="Singles Chart" theClass="S" case "TopAlbums" theTitle="Album Chart" theClass="A" case else theTitle="Not Found" end select |
switch ($chartName) { case "TopSales": $theTitle="Best Sellers"; $theClass="S"; break; case "TopSingles": $theTitle="Singles Chart"; $theClass="S"; break; case "TopAlbums": $theTitle="Album Chart"; $theClass="A"; break; default: $theTitle="Not Found"; } |
||
Functions and procedures |
Function myFunction(x) myFunction = x*16 'Return value End Function |
function myFunction($x) { return $x*16; //Return value } |
String Functions | |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HTTP Environment | |
GET, POST and other variables: Request.QueryString("name") Request.Form("name") Request.Cookies("name") |
Other variables: $_GET["name"] @$_GET["name"] (@ = ignore errors) $_POST["name"] $_COOKIE["name"] $_SERVER $_FILES $_ENV $_REQUEST $_SESSION |
|
|
|
|
|
|
|
|
|
|
File System Functions | |
|
|
|
|
|
|
Time and Date Functions | |
|
|
|
|
Numeric Functions | |
|
|
|
|
|
|
PHP 5's major new achievements come in the area of its exception handling and a new object that introduces features that bring true OOP to PHP. Exception handling was certainly one of the most noticeable missing features in PHP 4, and its addition to PHP 5 is certainly a sign of maturity. Exception handling means you have language defined and standardized ways of handling errors in your software. Just use the try, catch, and throw methods, and your PHP code becomes more robust and clean.
<?php class blue { function openFile ($inFile) { if (file_exists ($inFile)) { # code to open the file here } else { throw new Exception ("Cannot open file: $inFile"); } } } $blueObj = new blue (); try { $blueObj->openFile ('/home/shull/file.txt'); } catch (Exception $myException) { echo $myException->getMessage (); # rest of exception handling code here } # rest of blue methods here ?>
The new object model has a number of positive impacts on programs written in PHP. In PHP 4, when an object was passed to a function or method, it was passed by value, unless you explicitly told PHP otherwise. This procedure meant that a copy of that object, all the data structures in memory, would have to be copied. This step used memory and made access slow and clunky. In PHP 5, however, objects are always passed by reference.
The new object-oriented features in PHP 5, including constructors and destructors, are noteworthy. As with C++ and Java, they provide a standard way to create the object, allocate memory, and do any necessary setup via a constructor method and perform cleanup with a destructor method.
PHP 5 also introduces more subtle control of methods and variables in your classes. In PHP 4, everything was public: You could access variables from your classes outside the class or in derived classes. In PHP 5, you can still make variables or methods public, but you can also make them private, so they're used only within the class itself. A third option is to make them protected, which means that methods and variables can be viewed within the class or when subclassed.
Furthermore, PHP 5 introduces type hinting, or better type checking. When you pass an object into a routine, PHP can check that it is the right type and give a type-mismatch error if the check fails.
Additional features such as static methods and variables and abstract classes exist, so be sure to check the documentation for details.