• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CF2023: Elvis-operator don't work in extended component.

Community Beginner ,
Nov 29, 2023 Nov 29, 2023

Copy link to clipboard

Copied

Base.cfc:

 

component accessors="true" {
 public string function getFilterSql(required array filter) {
   ... filter["operator"] ?: ""  //null-exception
   ... filter.operator ?: ""  //null-exception
   ... isDefined('filter.operator') ? filter.operator : ""  //works
 }

 

Comp.cfc:

component extends="Base" rest="true" produces="application/json" restpath="xyz" {
 remote struct function getX() httpMethod="GET" {
  var filterSql = getFilterSql(filters);
 }
}

When I copy the function from Base.cfc into Comp.cfc ELVIS is working as it is suppose to.

Thank you in advance!

Views

119

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 29, 2023 Nov 29, 2023

Copy link to clipboard

Copied

It's possible it is failing because your function signature defines "filter" as an array, but you are using filter as a struct in the function body.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 29, 2023 Nov 29, 2023

Copy link to clipboard

Copied

Thanks for your reply EddieLotter!

"filter" contain an array of structures. As mentioned: When I copy the function from Base.cfc into Comp.cfc it works fine (without changing anyhing).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2024 Apr 07, 2024

Copy link to clipboard

Copied

LATEST
quote

When I copy the function from Base.cfc into Comp.cfc ELVIS is working as it is suppose to.


By @michaels14629018

 

You cannot yet be sure. The fact that you no longer get an error when you copy the function to Comp.cfc is not proof that things are working as they should. The code does in fact contain errors besides the null exception. Such errors just might be related to the null exception. In any case, it would help clarify the null problem if you first resolved all other issues.

For example,

  1.  The functions getFilterSql and getX both have return-types. Yet neither contains a return statement.
  2.  The argument of getFilterSql, filter, is an array, whereas the function uses it as if it were a struct (as @EddieLotter has pointed out) .
  3.  The function getX uses an undefined variable, filters

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation