Created
June 23, 2020 11:48
-
-
Save bennadel/a70a3b4f3c24b9c7bc18f0b6d64a1bb5 to your computer and use it in GitHub Desktop.
Scope Traversal Behavior With Undefined Function Arguments In Lucee CFML 5.3.6.61
This file contains hidden or 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> | |
data = [ | |
"a": nullValue(), | |
"b": "bee", | |
"c": nullValue() | |
]; | |
value = "The Spanish Inquisition"; | |
data.each( | |
( key, value ) => { | |
// CAUTION: When we reference VALUE here, ColdFusion is going to look for it | |
// in a cascading number of places. First, the LOCAL scope. Then, the | |
// ARGUMENTS scope. Then the VARIABLES scope. If VALUE is undefined in the | |
// lower-level scopes, ColdFusion will continue to look for it higher-up in | |
// the scope-chain. | |
echo( key & " : " & ( value ?: "[undefined]" ) & " <br />" ); | |
} | |
); | |
</cfscript> |
This file contains hidden or 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> | |
userService = new UserService(); | |
userService.createUserAccount( | |
name = "Ben", | |
email = "ben@bennadel.com", | |
password = "ourdeepestfearisnotthatweareinadequate" | |
); | |
</cfscript> |
This file contains hidden or 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
component | |
output = false | |
hint = "I provide method for access user accounts." | |
{ | |
public numeric function createUserAccount( | |
required string name, | |
required string email, | |
required string password, | |
string role | |
) { | |
var dbArguments = { | |
name: name, | |
email: email, | |
password: password, | |
// NOTE: If the role argument is undefined, we are going to fallback to a | |
// standard user. | |
// -- | |
// NOTE: If we provide a default value in the function signature, we would | |
// not have any issues here. | |
role: ( role ?: "user" ) | |
}; | |
systemOutput( serializeJson( dbArguments ), true, true ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment