return type confusion
ColdFusion
I thought that the expected behavior for a <cffunction> with a returntype other than void would be to throw an error in the event that nothing is returned.
<cffunction name="test" output="false" access="public" returntype="string"> <cfset var foo = "bar" /> <!--- Notice this code doesn't return anything, although the return type is defined as a string ---> </cffunction> <!--- Invoke the function ---> <cfset blah = test() /> <!--- Have a look at what's in here ---> <cfdump var="#blah#" />
The above code doesn't really do much, but it should throw an error, right? An error that "the value returned from the test function is not of type string", right? Au contraire ..


Needless to say I found this quite surprising. Shouldn't the method have exploded all over the place before I got the chance to evaluate the non-existing blah? I got even more confused when I changed the return type to numeric and saw something different:
Any thoughts? Shouldn't the behavior be the same in both cases? Isn't the second behavior the expected one? Would appreciate some help here.




Loading....