i allways thought, that the Concatenation Dot is to combine multiline-Strings. But today i ran into trouble doing the following:
if (strlen($col->getValue())>$col->getLength())
$this->errors[]=$name." ist ".
strlen($col->getValue())-$col->getLength().
" too much chars!";
i thought this to be one single line after the if-clause, but PHP evaluated line 2 and 3 after the if even when the condition wasn't given here. I needed to do some
if (strlen($col->getValue())>$col->getLength()) {
$this->errors[]=$name." ist ".
strlen($col->getValue())-$col->getLength().
" Zeichen zu lang!";
}
brackets around to get correct result instead of strange Parser errors. Am i understanding the concatenation-Sign usage wrong? I noticed the same when creating multi-line constants in classes ( i.E. prepared SQL Statements).
Does anybody know what i am doing wrong here. Any point i haven't seen?
You need to put parens around this expression:
(strlen($col->getValue())-$col->getLength())
Because you are using the horrible practice of not using braces with your if
. Only the first line following the condition is considered part of the condition.