Status/Resolution/Reason: Closed/Withdrawn/AsDesigned
Reporter/Name(from Bugbase): Aaron Neff / ()
Created: 05/10/2018
Components: Language, Null Support
Versions: 2018
Failure Type: Others
Found In Build/Fixed In Build: / 2018,0,0,309297
Priority/Frequency: Normal /
Locale/System: / Platforms All
Vote Count: 1
Issue: Aether Beta's null support allows non-void UDFs to return null. This breaks backward-compat where users expect the declared return type to be enforced.
Suggestion: Require a leading question mark symbol (?) to explicitly indicate a nullable type; otherwise the type is not nullable. Precedent: PHP 7.1.
Examples (with null support enabled):
<cfscript>
any function myAny1(){}//OK
any function myAny2(){return}//OK
any function myAny3(){return null}//OK
array function myArray1(){}//error
array function myArray2(){return}//error
array function myArray3(){return null}//error
?array function myArray1(){}//OK
?array function myArray2(){return}//OK
?array function myArray3(){return null}//OK
</cfscript>
When subtyping a return type the nullability can be removed by a subclass, but it cannot be added:
MyInterface.cfc:
interface {?array function myArray4()}
MyCFC.cfc:
component implements="MyInterface" {array function myArray4(){}}//valid
Related thread: https://forums.adobeprerelease.com/coldfusionpr/discussion/380/cf-4202295-null-support-removes-return-type-check
Related ticket: CF-4202295
Related URL: https://wiki.php.net/rfc/nullable_types
Credit: Adam Cameron, Sean Corfield, Denard Springle and Charlie Arehart.
Attachments:
Comments: