From ColdFusion to PHP
Although I've primarily been a ColdFusion developer for the last 10 years (at least during office hours), I'm starting work on a project where PHP is a logical choice so that's going to be my operating environment for a few weeks. I've done a fair amount of PHP work in the past, but it's been about 3 years. I'm about two days in and a few differences are already screaming at me.
The Missing Application.cfm
Okay, so this is just something I keep hearing about more than something I'm noticing. I know better. It's not missing. Let's clear up that little misconception right now. Sure, there's no Application.php file, per se, but there's a nifty little directive in the php.ini file that lets you specify a template to be included before every single request. There's a similar directive that allows you to select a template to be included at the end of every request. Look for the auto_append_file and auto_prepend_file directives, respectively.
If you're in a hosted environment or don't have access to the php.ini file for any other reason, I learned from this thread on the CF-Talk mailing list that you can still do what you need to do if your host is running an Apache web server. In lieu of modifying the php.ini file you can include the analogous directives in a .htaccess file. The syntax is php_value auto_prepend_file and php_value auto_append_file.
No Shared Scope Variables
This is easily the thing I miss the most in the transition to PHP. Easily. When I don't have shared scope variables, I think I find even more reasons that I'd like to use them. That cliche about not knowing what you have until it's gone really hits home for me on this one. For the longest time I just couldn't figure out why they weren't added. I mean, c'mon, it can't be that hard can it? Turns out that maybe it can.
I was doing some reading about a week ago and someone offered a reason in a forum post somewhere. I don't have the URI or the message, but as I recall, the reason is because each request to a PHP page spawns a separate PHP process. With ColdFusion, on the other hand, a single background process is running which spawns threads within that process. Hopefully I got that right. If not, I'm sure someone will be more than happy to correct me.
I still don't like it and I still miss shared scope variables, but understanding why I can't have them helps.
Ternary Operators
Holy crap, how I've missed these! Java supports them so I don't know why ColdFusion doesn't, but it's so nice to be able to use them again. Being able to use them at all is great, but the real power is being able to embed them within, say, a string concatenation. I love that.
Okay, that's a bad example since there's no useful else value in this case, but it's what I could come up with. Hopefully you get the idea. It's just cleaner than using cfif/cfelse sometimes.
Other Operators
Specifically, the increment/decrement operator (++/--) and assignment operators like +=, .=, etc. Like ternary operators, these are just...so...nice. I can't tell you how many times I've cfscripted a for loop only to get an error because I wrote for ( variables.i = 1; variables.i < arrayLen ( variables.myArray ); variables.i++ ). It's something I've become so accustomed to in other languages that I find myself forgetting that ColdFusion doesn't support it.




Loading....