Notice: Undefined index: msg in C:\xampp\htdocs\emovie24\index.php on line 7
use the isset method when you are not sure about a value. In your example, $_REQUEST['msg'] is not defined, hence the error.
You can use this:
if(isset($_REQUEST['msg']) && $_REQUEST['msg'] == "reg"){
echo "...";
}
which first checks that the value exists/is defined before doing any comparison.
Related
I am getting a TypeError on the following statement:
let uploadSignal = true;
mandatoryFields.forEach((element) => {
let field = this.state[element];
if(field.value === ""){
field.error = "Required!";
uploadSignal = false;
}
});
TypeError: Cannot read property 'value' of undefined
This means that you are trying to refer to a property called value on an undefined object. The only place you do that is here:
if(field.value === ""){
Which means field is undefined. field is being set here:
let field = this.state[element];
Which means this.state[element] is undefined.
i am asking why value is undefined and how to solve this error so that i can run my program
For the former, we can't know. You'll need to debug and discover what your runtime values are and why you expect this value to be defined. All we can say with certainty is that it's not.
For the latter, you can conditionally check if the value is "truthy" before trying to use it:
if(field && field.value === ""){
In the event that field is undefined then the left side of the && operation will be "falsy", which will cause the entire condition to be false without needing to evaluate the right ride of the && operation. With the condition being false, the if block isn't executed and the code continues.
Problem Statement
I am using TypeScript's find() method for an array, but when I input a value, it does not work and says, "No overload matches this call".
Code
addOption(event: MatChipInputEvent) {
const input = event.input;
const value = event.value;
// Makes sure that the same element is not inserted in the the options array
if (value !== this.options.find(value)) {
// Add our option
if ((value || '').trim()) {
this.options.push(value.trim());
}
}
// Reset the input value
if (input) {
input.value = '';
}
}
Explanation of Code
As you can see, I am using the find method in the first if condition to check and prevent the same element from coming into the array. The value you see there has a red underline and gives me the error, "No overload matches this call". I seem to be doing everything syntactically correct but the error is still there.
Actual Results
The find method gives me the error, "No overload matches this call" and does not accept the value in the parameters.
Expected Results
The find method to take in the value and find the element in the array.
Instead of find, you should use includes.
if (!this.options.includes(value)) {
In case you really want to use find, it can be done as follows:
if (this.options.find(o => o === value) == undefined) {
I am stuck with an AngularJS filter issue and would appreciate an advise. In several different views I have numbers, like 1000000000, which are hard to read. Task is to separate each three digits' block by commas. To do that I have written a filter:
angular.module('AppCore')
.filter('numberCommaSeparator', function () {
return function (x) {
x = x.toString();
var pattern = /(-?\d+)(\d{3})/;
while (pattern.test(x))
x = x.replace(pattern, "$1,$2");
return x;
}
});
Added the filter in the view:
<span ng-if="project.value != 0">{{project.currency.name}} {{project.value|numberCommaSeparator}}</span>
<span ng-if="project.value == 0">N/A</span>
In two places out of three it works flawlessly, however, in the third case I do constantly receive a mistake:
Error: [$interpolate:interr] Can't interpolate: {{project.currency.name}} {{project.value|numberCommaSeparator}}
TypeError: Cannot read property 'toString' of undefined
What am I missing?
The error says that in some case your project.value is undefined
If that value is undefined, the first ng-if condition project.value != 0 is satisfied, not the second, you should check also for undefined to avoid that error.
Overview
I am new to the Swift language, but not others, and am having trouble executing a simple Array.filter statement that I would like to return as the result for a function in a class I am writing, but it seems adding the return keywords causes non-intuitive compile errors.
Question: Does anyone know what to make of these error messages, and how to fix them?
Samples
Declarations
var arrDictIVar = [["dictVar1": "value"]]
...
func someFunc(var1: String) {...
Various Trials
Set 1
return arrDictIVar.filter({
$0["dictVar1"] == var1
})
return arrDictIVar.filter(){
$0["dictVar1"] == var1
}
return arrDictIVar.filter{
$0["dictVar1"] == var1
}
Error: Cannot invoke 'filter' with an argument list of type '(#noescape ([String : String]) throws -> Bool)'
Error Subtext: Expected an argument list of type '(#noescape (Self.Generator.Element) throws -> Bool)'
Source: Sample MCVE Execute here
Set 2
return arrDictIVar.filter({
$0["dictVar1"] == var1
})[0]
return arrDictIVar.filter() {
$0["dictVar1"] == var1
}[0]
return arrDictIVar.filter{
$0["dictVar1"] == var1
}[0]
Error: Cannot subscript a value of type '[[String : String]]'
Source: Sample MCVE Execute here
Set 3
arrDictIVar.filter({
$0["dictVar1"] == var1
})
arrDictIVar.filter(){
$0["dictVar1"] == var1
}
arrDictIVar.filter{
$0["dictVar1"] == var1
}
Warning: Result of call to 'filter' is unused
Note: Just to show that the block is properly formed without the return keyword.
Source: Sample MCVE (Execute here)
Other Information
I have also tried modifying the IVar declaration to var arrDictIVar: Array<Dictionary<String,String>> = [..., and the function declaration to func someFunc(var1: String) -> Dictionary<String,String>{... at various times, with similar failures.
Edit: I had posted an answer at the same time of this question as I found a combination that worked towards nearing the end of this posting. It does include changing the return data type in the method signature, along with giving other information alluding to the inaccurate, or at least confusing nature, of the compiler, and the error messages it presents.
After this I was left with a follow-up question:
If anyone would be able to explain why this was happening, and give a clear judgement as the compiler error message was not as helpful as it could be, my reading/interpretation of the error message was not as clear as it could have been, potentially saving time by changing my mindset somehow, or either, please comment on that note.
Victor Sigler's answer does seem to cover this in some good detail.
Let's explain in detail every set you have put in your question:
Set 1:
Your three examples are right in code and are the same to the compiler, you're using a trailing closure and the parentheses can be omitted.
Sometimes the compiler(because it's so young yet!!!) not show the exactly error happening in your code, but definitely in this step you're using the filter function to return an [[String: String]] or an array of dictionaries and you're missing the type of the return of the function, it's assumed by the compiler as Void.
About #noescape:
Adding #noescape guarantees that the closure will not be stored somewhere, used at a later time, or used asynchronously. Remember that closures capture values.
You can read more about the #noescape clause in the following two very good tutorials:
#noescape Attribute
Hipster Swift: Demystifying the Mysterious — KrakenDev
So to resume it, if you change your function to the following it should work:
func someFunc(var1: String) -> [[String: String]] {
return arrDictIVar.filter({
$0["dictVar1"] == var1
})
}
Set 2:
If you fix the error in the Set 1 then when you code:
return arrDictIVar.filter{
$0["dictVar1"] == var1
}[0]
You're trying to return a [String: String] or a dictionary and it's wrong regarding the return type of the function it's [[String: String]].
But be careful because if you change the return type to [String: String] and try to index the array returned for the filter function and there is nothing founded by the filter function you would get an runtime error.
Set 3
I think it is the more easy to understand because as the warning said, the filter function returns a new list of elements and if you don't save it or returned in your function it's unused, something like this:
func someFunc(var1: String){
arrDictIVar.filter({
$0["dictVar1"] == var1
})
}
I hope this help you.
I am having a strange problem...I have set up a cfscript for use in creating a datatables JSON object, and occasionally I am receiving an unhandled exception error "the element at position X cannot be found" The X typically is one more than my array actually has, so in my case, i have 44 elements in an array, the expression error always states "position 45 cannot be found"
heres some code
/* 44 total items in this array*/
aColumns = ['nd_event_group_id','nd_event_id', 'pref_mail_name', 'request_status_code', "life_gift_pledge_ob_amt", 'activity', ... ];
/* this will return 44 */
iColumnsLen = ArrayLen(aColumns);
...
savecontent variable="rc.aaData" {
for (i=1; i <= rc.qResult.RecordCount ; i++) {
writeOutput('{');
for (col=1; col <= iColumnsLen; col++) {
// the next line is what is referenced by the expression error
// "The element at position 45 cannot be found"
writeOutput('"#aColumns[col]#":#SerializeJSON(rc.qResult[aColumns[col]][i])#');
writeOutput((col NEQ iColumnsLen) ? ',' : '');
}
writeOutput('}');
writeOutput((i NEQ rc.qResult.RecordCount ) ? ',' : '');
}
};
The strange part about this issue is that I cannot recreate the error with any precision, its a hit or miss thing that occasionally happens
this script is ran by a GET via AJAX
any ideas?
Deriving this from the comments posted, it sounds like you have variables unVARed. All function-local variables need to be declared as such, either with the VAR keyword, or by specifically scoping them in the LOCAL scope.
If you don't do this, variables are global to the CFC instance, and accordingly shared between functions. This sounds like your problem.
This is all in the docs: "CFC variables and scope".