Download Firefox -  a safer, easier to use web browser. Return to iribbit.net - Leap into the online experience! Return to iribbit.net - Leap into the online experience! iribbit.net - Leap into the online experience!

Project News :.

The latest project to launch was the site for Gorilla Offroad Company. Aside from their main site, a social media strategy was develop to launch the company into various industry specific automobile enthusist discussion board communities as well as popular social media fronts like Facebook, Pinterest, and Twitter.


Valid XHTML 1.0 Transitional

Valid CSS!

Section 508 Compliant

powered by: Macromedia ColdFusion MX

made with: Macromedia Dreamweaver MX

What is RSS

XML - often denotes RSS Feed information.

Macromedia - ColdFusion Programming
white horizontal rule

ColdFusion News :.

To bring a little life to my site, I've pulled a couple What is RSS Feeds into this page. You can currently choose between the technology related news stories from the following news sources:



You are currently viewing and RSS Feed from coldfusionbloggers.org.



Spicing up Eclipse with Themes

I just stumbled upon this site today: http://eclipsecolorthemes.org after spending so much time on dark IDE themes and going back to ColdFusion Builder, I was getting a nice headache. I quickly downloaded and installed some nice themes from here and voila! ColdFusion Builder has come to life with some great new dark themes. Here is a screenshot of my IDE now:

Enjoy!


(Thu, 18 Sep 2014 18:00:17 GMT)
[view article in new window]

Simplified Body Glide package design

I love seeing a piece of design go from "amateur Photoshopper" to simple and clean. See this quick post on how Body Glide delighted my inner design nerd recently with their package redesign.


(Thu, 18 Sep 2014 12:00:22 GMT)
[view article in new window]

Configuring Apache on Mac OS X (Mavericks) for Python scripting
I spent a couple of hours today trying to figure out how to configure Apache Web Server on Mac OS X to execute Python scripts, so I thought I would document the process for my own reference. OS X is … Continue reading
(Thu, 18 Sep 2014 08:00:18 GMT)
[view article in new window]

Datalist support in Mobile Chrome
iOS8 launched yesterday and it has damn good updates in mobile Safari. I strongly suggest folks read Max Firtman's detailed review here: iOS 8 and iPhone 6 for web developers and designers: next evolution for Safari and native webapps. One thing mi...
(Thu, 18 Sep 2014 08:00:15 GMT)
[view article in new window]

CFScript docs now on GitHub
G'day:
That CFScript documentation thing I released the other day ("Documentation for CFScript") is now on Github @ "CFScript documentation".

Currently it's a duplicate of the stuff on the blog article, but the GitHub one will be treated as the master copy from now on. I am in the process of simply embedding that back into the original article so that the article is always current. I should have that done in the next day or so.

So... if you find anything wrong with those docs... you can fix 'em yerself. Just send me a pull request.

Just an aside. A coupla people have said those docs would be better if they cross-referenced the CFScript code back to their tag equivalents. I think this is an arse-about-face way of thinking about CFScript and CFML in general. CFScript should be the primary syntax used in CFML, and tags should only be used in views. And most tags should not be used at all. I do not want to present the CFScript documentation as if it's a mapping to the tags. It should not be thought of that way.

That document serves to document CFScript. So intrinsically: tags have nothing to do with it. The exception here is in the last section where I describe the generic syntax patterns, as that's unavoidable due to Railo & Adobe's thoughtless/lazy approach to rounding out CFScript's functionality where previously there were only tag-based solutions to various bits of functionality, and their "solution" was to base the CFScript syntax directly on the existing tag syntax.

If someone else wants to create their own doc based on this one which maps tags to script and/or vice versa, go for it.

Cheers.

--
Adam
(Thu, 18 Sep 2014 06:43:15 GMT)
[view article in new window]

You Can Reference Your Derived SELECT Columns In Your ORDER BY Clause In SQL
Ben Nadel demonstrates that derived columns in the SELECT statement can be referenced directly in the ORDER BY clause of a SQL statement....
(Thu, 18 Sep 2014 04:00:14 GMT)
[view article in new window]

PHP equivalence to getFunctionCalledName()
G'day:
I touched on this in the last article: "Looking at PHP's OOP from a CFMLer's perspective: overloading (which is not what you'd assume it is)". PHP has a magic constant __FUNCTION__ which returns the name of the function being called. I claimed it's kinda like getFunctionCalledName() in CFML. But not quite. Let's have a look.

(This will be a pretty short article, I think).

CFML: getFunctionCalledName()

As a recap, here's some CFML code demonstrating getFunctionCalledName():

// getFunctionCalledName.cfm

function f(){
echo("#getFunctionCalledName()#() called<br>");
}

f();
echo("<hr>");

g = f;
g();

This outputs:

F() called

G() called

Note that despite the function being declared as f(), getFunctionCalledName() "knows" the latter call to it was via the reference g. OK. That's the baseline expectation set.

PHP equivalent: __function__?

(Betteridge alert!)

Here's the equivalent PHP code using __function__:

<?php
// testFunction.php

function f()
{
echo sprintf("Using __FUNCTION__: %s() called<br>", __FUNCTION__);
}

f();
echo "<hr>";

$g = "f";
$g();

And this outputs:

Using __FUNCTION__: f() called

Using __FUNCTION__: f() called

Hmmm. So __FUNCTION__ always returns the function with its defined name.

On a whim, let's see what happens with a function expression:

<?php
// testFunctionExpression.php

$f = function () {
echo sprintf("Using __FUNCTION__: %s() called<br>", __FUNCTION__);
};

$f();
echo "<hr>";

$g = $f;
$g();


Result:

Using __FUNCTION__: {closure}() called

Using __FUNCTION__: {closure}() called

"closure". Harrumph. But anyway, that's along the lines of what I expected. Pleasingly, the syntax for a function expression is the same as CFML, so I was able to correctly guess that. Win.

debug_backtrace()?

So how do we find the actual name the function was called with?

Googling about I found a lot of references to debug_backtrace(), which is worth looking at:

<?php
// debugBackTraceDump.php

require "../../debug/dBug.php";

function f()
{
new dBug(debug_backtrace());
}

f();
echo "<hr>";

$g = "f";
$g();

Result:

debug_backtrace() (array)
0
array
fileD:\Websites\www.scribble.local\shared\scratch\php\www\experiment\constants\debugBackTraceDump.php
line11
functionf
args
array

debug_backtrace() (array)
0
array
fileD:\Websites\www.scribble.local\shared\scratch\php\www\experiment\constants\debugBackTraceDump.php
line15
functionf
args
array

Well it's handy to know about debug_backtrace(), but it's no help to us here.

Nope

More googling... and I've drawn a blank.

Maybe I have to pop my head above the parapet on Stack Overflow and ask a question? Shudder. Done: "PHP: Get the name a function was called as, equivalent to CFML's getFunctionCalledName()".

--
Adam
(Wed, 17 Sep 2014 12:57:10 GMT)
[view article in new window]

PHP equivalence: onMissingMethod()
G'day:
Whilst looking at overloading in PHP before ("Looking at PHP's OOP from a CFMLer's perspective: overloading (which is not what you'd assume it is)"), I thought I might need to write an equivalent on onMissingMethod(), to catch instances of me calling... methods which I expected not to exist. I didn't need to because PHP works differently form how I expected it to, but it piqued my interest so I've just looked up how this is done. It's easy.



Here's a CFML example:

// Missing.cfc
component {
public function onMissingMethod(name, args) {
writeDump(arguments);
}
}

// missing.cfm
missing = new Missing();

missing.nonExistent("first",["second"]);

Nothing out of the ordinary there. It outputs:

Scope Arguments
name1
stringnonExistent
args2
Scope Arguments
11
stringfirst
22
Array
1
stringsecond

So the first argument is the function that was called (and does not exist), and the second are the arguments passed to it.

Very similarly, here's the PHP equivalent:

<?php
// Missing.class.php

class Missing
{

public function __call($name, $arguments)
{
require "../../../debug/dBug.php";
new dBug(func_get_args());
}
}

<?php
// missing.php

require "Missing.class.php";

$missing = new Missing();

$missing->nonExistent("first", ["second"]);

And the output here is:

func_get_args() (array)
0nonExistent
1
array
0first
1
array
0second

So __call() is the PHP equivalent of onMissingMethod(), and works pretty much the same way.

PHP also has the notion of static methods, and there's a handler for missing static methods too. Here's a variation of the above code... the difference is basically we use __callStatic() instead:
<?php
// Missing.class.php

require "../../../debug/dBug.php";

class Missing
{

public function __call($name, $arguments)
{
echo sprintf("Function called: %s", __FUNCTION__);
new dBug(func_get_args());
}

public static function __callStatic($name, $arguments)
{
echo sprintf("Function called: %s", __FUNCTION__);
new dBug(func_get_args());
}
}


<?php
// missing.php

require "Missing.class.php";

$missing = new Missing();

$missing->nonExistent("first", ["second"]);
echo "<hr>";

Missing::nonExistent("tuatahi", ["tuarua"]);

This outputs:

Function called: __call
func_get_args() (array)
0nonExistent
1
array
0first
1
array
0second

Function called: __callStatic
func_get_args() (array)
0nonExistent
1
array
0tuatahi
1
array
0tuarua

So that's straight forward too.

I realise there's not much insight to this article, but I just wanted to share when things go smoothly as well as when I get undone by weirdness / ignorance.

--
Adam
(Wed, 17 Sep 2014 12:57:10 GMT)
[view article in new window]

Looking at PHP's OOP from a CFMLer's perspective: overloading (which is not what you'd assume it is)
G'day:
This is the fifth part of a series. The first four parts are here:
Today I'm looking quickly at a PHP concept called "overloading". Which has nothing to do with the usual OO concept of "overloading", either in the sense of same-named methods with different signatures, or operator overloading. In fact I seriously dunno why they called this construct overloading at all.

In PHP parlance "Overloading" is basically a mix of what in CFML we'd refer to as synthesised and implicit accessors.

First up, here's a CFML recap.

Synthesised accessors

Synthesised accessors (often erroneously referred to as implicit accessors, which is a different thing entirely: see further down). This is a feature of CFML wherein one can explicitly call getter or setter methods on an object without the relevant accessor being defined. EG:

// Number.cfc
component accessors=true {

property english;
property maori;

public function onMissingMethod(){
writeDump(var=arguments, label="#getFunctionCalledName()#() call caught by onMissingMethod()");
}


}

// testNumber.cfm

number = new Number();
number.setEnglish("toru");
number.setMaori("three");

number.setJapanese("三");


writeDump(var={
english = number.getEnglish(),
maori = number.getMaori()
}, label="From getters");

Here I have a simple CFC with two properties specified: english and maori, and the only method is onMissingMethod(), which is only used to demonstrate what happens when we call an accessor on a non-existent property.

The test code calls setEnglish() and setMaori(), which are synthesised setters for the english and maori properties. It also calls setJapanese() which is not a synthesised setter, as there is no such properly as japanese in this example.

The results are as follows:

onmissingmethod() call caught by onMissingMethod()
Scope Arguments
11
stringsetJapanese
22
Scope Arguments
11
string
From getters
Struct
ENGLISH
stringtoru
MAORI
stringthree

Note that setEnglish() and setMaori() do not trigger onMissingMethod() despite not actually being defined in the component; yet they still work fine, and set the properties correctly. On the other hand setJapanese() doesn't exist, and is simply caught by onMissingMethod().

Implicit Accessors

CFML also has implicit accessors (this needs to be switched on in Application.cfc). Implicit accessors are invoked implicitly (ie: without explicitly using them) when a property of a CFC is accessed. Here's an example:

// Application.cfc
component {
this.invokeImplicitAccessor = true;
}

// Person.cfc
component {

property firstName;
property lastName;

public string function getFirstName(){
writeOutput("#getFunctionCalledName()#() called<br>");
return firstName;
}

public void function setFirstName(firstName){
writeOutput("#getFunctionCalledName()#() called with #firstName#<br>");
variables.firstname = arguments.firstName;
}

public string function getLastName(){
writeOutput("#getFunctionCalledName()#() called<br>");
return lastName;
}

public void function setLastName(lastName){
writeOutput("#getFunctionCalledName()#() called with #lastName#<br>");
variables.lastName = arguments.lastName;
}


}

// testPerson.cfm

person = new Person();
person.firstName = "Donald";
person.middleName = "Adam";
person.lastName = "Cameron";


writeOutput("Full name: #person.firstName# #person.lastName#<br>");

writeDump(person);

This time the accessor methods are defined, but they are never called. Simply referencing the property implicitly calls either the setter or the getter for it, as appropriate. Output:

setfirstname() called with Donald
setlastname() called with Cameron
getfirstname() called
getlastname() called
Full name: Donald Cameron

Component (Person) 
Only the functions and data members that are accessible from your location are displayed
public
MIDDLENAME
stringAdam
GETFIRSTNAMEvar.GETFIRSTNAME
GETLASTNAMEvar.GETLASTNAME
SETFIRSTNAMEvar.SETFIRSTNAME
SETLASTNAMEvar.SETLASTNAME

The thing to note here is that the setters and getters for firstName and lastName are indeed being invoked, despite no explicit reference to them. Also note that setting middleName does not result in any special action, it just sticks a variable into the this scope of the object.

Combining synthesised and implicit accessors

And the two concepts can be combined. Here's an example where the accessors are synthesised, and they are called implicitly:

// Day.cfc
component accessors=true {

property english;
property maori;

}

// testDay.cfm

day = new Day();
day.english = "Tuesday";
day.maori = "Rātū";
day.japanese= "火曜日";

writeDump(day);

I'll not pore over this, but it just demonstrates there's no accessor methods defined, plus we never call them. But - as if by magic - the behaviour is as if they were there and they were called:

Component (Day) 
Only the functions and data members that are accessible from your location are displayed
Properties
english
stringTuesday
maori
stringRātū
public
getMaorivar.getMaori
setEnglishvar.setEnglish
getEnglishvar.getEnglish
JAPANESE
string火曜日
setMaorivar.setMaori

Note that Railo actually does create the methods for me, behind the scenes. Note also that the japanese value is simply treated as an assignment of a this-scoped variable in the day object.

So that's the CFML scene set. How does PHP deal with this?

Overloading

I have no idea why PHP decided to call this overloading. Even PHP itself realises the confusion it would cause by co-opting an established term and using it to mean something different. This is from the docs:
Note:
PHP's interpretation of "overloading" is different than most object oriented languages. Overloading traditionally provides the ability to have multiple methods with the same name but different quantities and types of arguments.
So they knew they were doing something stupid, and still did it anyhow. This is reminiscent of some decisons Adobe has made with CFML. Except generally Adobe seem to be completely oblivious to poor decisions they make, I dunno which is worse. But I digress.

<?php
// Person.class.php

class Person
{
private $firstName;
private $lastName;
private $sex;

public function __set($name, $value)
{
echo sprintf("%s() called with %s, %s<br>", __FUNCTION__, $name, $value);
$this->$name = $value;
}

public function __get($name)
{
echo sprintf("%s() called with %s<br>", __FUNCTION__, $name);
return $this->$name;
}

public function __isset($name)
{
echo sprintf("%s() called with %s<br>", __FUNCTION__, $name);
return isset($this->$name);
}

public function __unset($name)
{
echo sprintf("%s() called with %s<br>", __FUNCTION__, $name);
unset($this->$name);
}

public function setSex($sex)
{
$this->sex = $sex;
}

public function getSex()
{
$this->sex = $sex;
}


}

So PHP goes wild with its underscores again here. Neat :-/

Overloading provides a number of methods __set(), __get(), __isset(), __unset() which are implicitly invoked when a property is accessed. One cool thing here is that as well as the obvious getter/setter treatment, it also caters for when testing if the property is set, and also when the property is "unset" (see example below). It's ugly as hell, but it all works OK.

We've also got another even more egregious underscore fiesta with the __FUNCTION__ "magic constant". It's kinda (kinda) like getFunctionCalledName() in CFML. I'll do another quick article about this shortly.

One quick thing to note in this code is this:

$this->$name = $value;

Note that this is different from a normal literal property assignment, eg:
$this->firstName = $firstName;

In the former example, the name of the key being set is itself a variable, not a literal as per the latter example. So in the __set() (etc) methods, the $name variable is the name of the property. Not a property called "name", if that makes sense. Same as doing this[name] in CFML.

Here's the test harness:

<?php
// test.php

require "Person.class.php";

$person = new Person();
$person->firstName = "Donald";
$firstName = $person->firstName;
echo "First name: $firstName<br>";
echo "<hr>";

if (!isset($person->lastName)){
$person->lastName = "Cameron";
}
$lastName = $person->lastName;
echo "Last name: $lastName<br>";
unset($person->lastName);
echo "<hr>";

$person->middleName = "Adam";
$middleName = $person->middleName;
echo "Middle name: $middleName<br>";
echo "<hr>";

$person->sex = "Male";
$sex = $person->sex;
echo "Sex: $sex<br>";


This is simple (and much the same as the CFML example above). Here I test setters, getters, isset() and unset(). I also set/get a property which is not previously defined, for good measure. Result:

__set() called with firstName, Donald
__get() called with firstName
First name: Donald



__isset() called with lastName
__set() called with lastName, Cameron
__get() called with lastName
Last name: Cameron
__unset() called with lastName


__set() called with middleName, Adam
Middle name: Adam



__set() called with sex, Male
__get() called with sex
Sex: Male


Observations:
  • The handling of $firstName and $lastName is predictable.
  • There seems to be a slight glitch when using overloading with undeclared properties: the __set() is called, but the __get() isn't? However the value is still fished out correctly. Weird. I have some googling to do there.
  • If a property has explicit accessors defined, they are not called. The docs made no claim to, but it'd be nice if they were. The implementation seems incomplete to me here.
Results of googling:
I found the answer to the issue with __get() not being called on access to $middleName. It had come up on Stack Overflow: "__get is not called if __set is not called, however code works?". It's not exactly the same, but this explains it:
In your second example, you assigned a value to a property in your object. Since you did not declare the property in your object, it gets created by default as public. Since its public, __get is never called when accessing it.
So this is actually working the same as the middleName & japanese examples from the CFML demos. Cool. Thanks, Stack Overflow.

I probably waffled on more about CFML in this than PHP, but it took me a while to refresh my memory on how CFML worked to contrast it with PHP, and to check my expectations.

OK, next I'm gonna have a look at this __FUNCTION__ thing...

--
Adam
(Wed, 17 Sep 2014 12:57:10 GMT)
[view article in new window]

PHP: references
G'day:
Yeah, it's been a busy day today. But I'm quite pleased with the PHP stuff I've learned. This is another quick one (OK, I'll stipulate now: a lot of these PHP ones will be short, so I'll stop saying that), and harkens back to something I talked about re CFML back in 2012: "Complex data-types in CF, and how they're not copied by reference".

PHP has a concrete and code-controllable notion of references; not just something that happens under the hood like in CFML.

I'll not go into what references are. You can read the PHP docs regarding references: "What References Are", or the language-neutral Wikipedia page: "Reference (computer science)".

CFML

Let's start with CFML though. In CFML we don't have any control over whether a piece of data is passed by value or passed by reference (I use that term incorrectly, but for expedience. Read the blog article I link to above for an explanation). Simple types and arrays are passed by value in CFML (Railo passes arrays by reference, that said), and other complex types are passed by reference.

Here's some example code which demonstrates CFML behaviour:

// references.cfm

original = "tahi,rua,toru";
copy = original;

original &= ",wha";
copy &= ",rima";


writeOutput("original: #original#<br>copy: #copy#<br>");
writeOutput("<hr>");

original = {"red"="whero", "orange"="karaka", "yellow"="kowhai"};
reference = original;

original["green"] = "kakariki";
original["blue"] = "kikorangi";

writeDump(original);
writeDump(reference);
writeOutput("<hr>");

reference = "and now for something completely different";
writeDump([original,reference]);
writeOutput("<hr>");

This outputs:

original: tahi,rua,toru,wha
reference: tahi,rua,toru,rima

struct
bluekikorangi
greenkakariki
orangekaraka
redwhero
yellowkowhai
struct
bluekikorangi
greenkakariki
orangekaraka
redwhero
yellowkowhai

array
1
struct
bluekikorangi
greenkakariki
orangekaraka
redwhero
yellowkowhai
2and now for something completely different


Here the assignment operator copies the value of the string original, and makes a duplicate of it as copy. They are two difference strings, so appending to one does not impact the other.

On the other hand when dealing with complex objects like a structure, the assignment operator creates a new variable which has a new reference pointing to the original. So it's not a "copy by reference" situation, but it's a similar "copy of reference" situation (I dunno the official term for this approach). The ramification is that adjustments made to the original are reflected in the reference to it, and vice versa. However if one gives the reference a new value completely, it does not change the original, because it overwrites that variable's reference with a new one to the new data.

If that's not clear, that other blog article I link to above goes through it thoroughly.

PHP

PHP has the ability to specify how assignments are made. One can do this:

$reference = &$original;

The ampersand indicates to make a new reference to the same data. The reference is the same, there's just a new variable pointing to that reference. In CFML's case there's a new variable, a new reference, just the new reference points to the same data as the original reference.

Here's some PHP code showing references in action. It's an approximation of the CFML code above.

// references.php

require "../../debug/dBug.php";

$original = "tahi,rua,toru";
$copy = $original;
$reference = &$original;

$original .= ",wha";
$reference .= ",rima";
$copy .= ",ono";

echo "original: $original<br>reference: $reference<br>copy: $copy<br>";
echo "<hr>";

$original = ["red"=>"whero", "orange"=>"karaka", "yellow"=>"kowhai"];
$reference = &$original;
$copy = $original;

$original["green"] = "kakariki";
$original["blue"] = "kikorangi";
$copy["indigo"] = "poropango";

new dBug($original);
new dBug($reference);
new dBug($copy);
echo "<hr>";

$reference = "and now for something completely different";
echo "original: $original<br>reference: $reference<br>";
new dBug($copy);
echo "<hr>";

And the output:

original: tahi,rua,toru,wha,rima
reference: tahi,rua,toru,wha,rima

copy: tahi,rua,toru,ono

$original (array)
redwhero
orangekaraka
yellowkowhai
greenkakariki
bluekikorangi
$reference (array)
redwhero
orangekaraka
yellowkowhai
greenkakariki
bluekikorangi
$copy (array)
redwhero
orangekaraka
yellowkowhai
indigoporopango

original: and now for something completely different
reference: and now for something completely different

$copy (array)
redwhero
orangekaraka
yellowkowhai
indigoporopango


There's a few things to note:

  • the $reference string points to exactly the same string in memory as the $original one. So change one: it's reflected in the other.
  • however the $copy string is completely different:changes to it apply only to it, and not the $original.
  • PHP will copy an array (bear in mind PHP doesn't have structs, it's just got "associative arrays"... that's a story for another day though) by value if you don't tell it otherwise. as demonstrated by the $copy.
  • Making a reference to an array now seems to behave like CFML does.
  • However if one does not do it with a reference, it makes a new copy, so changes to the copy are specific to the copy.
  • Until one gives that reference an entirely new value... the new value goes into memory pointed to by both the $original and $reference references, so original takes that new value. This demonstrates the difference between proper "assign by reference" and that which CFML does.

So why would one want to do this? one does it mostly with function arguments, eg:

function increment(&$x)
{
$x++;
}

$i = 0;
echo "\$i before: $i<br>";
increment($i);
echo "\$i after: $i<br>";

This outputs:
$i before: 0
$i after: 1

Here increment() takes a reference to $i as its $x argument value, so when $x is incremented... so is $i. This is a pretty dumb use case for using references though. They come into their own when dealing with large bits of data: we don't want to be copying huge objects / arrays / strings about the place when passing 'em to functions... usually just a reference is fine. This saves processing overhead and memory. One just needs to be mindful that when a function takes a reference, the value referenced could be changed by the function. So one needs to tread with caution.

I think this would be a good feature for CFML, and I have added an enhancement request which is being considered for uptake: 3638235. I had not raised it for Railo, but I have now: RAILO-3209.

--
Adam
(Wed, 17 Sep 2014 12:57:10 GMT)
[view article in new window]


© The connection to the COLDFUSIONBLOGGERS's RSS feed has timed out - please try again later. We are sorry for any inconvenience this may have caused.