Created
February 26, 2016 11:26
ColdFusion Can Safely Pull-Through NULL Values In Function Return Statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
public any function this_returns_null() { | |
// No actual return value - will be null / undefined. | |
} | |
public any function this_pulls_through_return_value() { | |
// Here, we are directly pulling-through the return value of the given method | |
// call as our own method's return value. | |
return( this_returns_null() ); | |
} | |
public any function test_null_return() { | |
// In this case, rather than pulling the return value though as our own return | |
// value, we're going to store the return value in an intermediary variable | |
// before we return it. | |
var intermediary_return_value = this_pulls_through_return_value(); | |
// Return the INTEMEDIARY value. | |
return( intermediary_return_value ); | |
} | |
// ------------------------------------------------------------------------------- // | |
// ------------------------------------------------------------------------------- // | |
try { | |
// Try to invoke the method that returns a null value being pulled-through | |
// from another method that returns a null value. | |
value = test_null_return(); | |
// Because we are returning null, ColdFusion will destroy the "value" variable. | |
// As such, if everything WORKS, the value will no longer exist. | |
if ( isNull( value ) ) { | |
writeOutput( "Successfully pulled-through NULL return values!" ); | |
} | |
} catch ( any error ) { | |
writeOutput( "Something broke: #error.message#" ); | |
} | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
public any function this_returns_null() { | |
// No actual return value - will be null / undefined. | |
} | |
public any function this_pulls_through_return_value() { | |
// Here, we are directly pulling-through the return value of the given method | |
// call as our own method's return value. | |
return( this_returns_null() ); | |
} | |
public any function test_null_return() { | |
// Here, we are directly pulling-through the return value of the given method | |
// call as our own method's return value. | |
return( this_pulls_through_return_value() ); | |
} | |
// ------------------------------------------------------------------------------- // | |
// ------------------------------------------------------------------------------- // | |
try { | |
// Try to invoke the method that returns a null value being pulled-through | |
// from another method that returns a null value. | |
value = test_null_return(); | |
// Because we are returning null, ColdFusion will destroy the "value" variable. | |
// As such, if everything WORKS, the value will no longer exist. | |
if ( isNull( value ) ) { | |
writeOutput( "Successfully pulled-through NULL return values!" ); | |
} | |
} catch ( any error ) { | |
writeOutput( "Something broke: #error.message#" ); | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment