|
Fusebox Migration: From ColdFusion to PHP
November 18, 2001
|
::: The Basics: miscellaneous :::
|
A couple other essentials to programming Fusebox applications are conditionals like if... then... else or switch... case..., conditional operators, and commenting.
The following are equivalents*:
In ColdFusion:
| |
<cfif Len(Trim(foo)) AND foo NEQ "bar">
<cfoutput>
A man walks into a #foo#, and says, "Ouch!"
</cfoutput>
<cfelse>
<cfset error="Please enter a value for <b>foo</b>, other than 'bar'.">
</cfif>
|
In PHP:
| |
<?php
if(strlen(trim($foo)) && $foo != "bar") {
print "A man walks into a $foo, and says, \"Ouch!\"";
} else {
$error = "Please enter a value for <b>\$foo</b>, other than 'bar'.";
}
?>
|
You'll notice the PHP has special characters where the ColdFusion uses words. AND and && are the same, and NEQ and != also match up. There are many of these types of differences in syntax, but I can't possibly cover them all here. Nor would I want to when there is already a fabulous resource available at http://www.php.net/manual/.
A switch block is what we in the Fusebox world call the "Fusebox". Not a big difference there again just syntax differences:
In ColdFusion:
| |
<cfswitch expression="#Fusebox.fuseaction#">
<cfcase value="main">
[...]
</cfcase>
<cfcase value="this,that,other" delimeters=",">
[...]
</cfcase>
<cfdefaultcase>
[...]
<cfdefaultcase>
</cfswitch>
|
In PHP:
| |
<?php
switch($Fusebox["fuseaction"]) {
case "main":
[...]
break;
case "this":
case "that":
case "other":
[...]
break;
default:
[...]
break;
}
?>
|
Finally, we all know that good programmers comment their code. In ColdFusion, comments look just like they do in HTML, but with one more "-" (hyphen). In PHP there are actually three ways to write comments:
In ColdFusion:
| |
<!--- I am a single-line comment --->
<!---
but I really
could go on
and on
for a few lines
--->
|
In PHP:
| |
<?php
//I am a single-line comment
# and I am also a single-line comment
/*
but if I want to
go on for a while
I need to use
a different style
*/
?>
|
Next, on to the good stuff!
|