What miracles happen in if from php?

I axe. Code:
function tvcap($tvname) {
 global $modx;
 if ($tvname == 0) {
 return 'Err. tvname=' . $tvname;
}
 $tv = $modx->getObject('modTemplateVar', array('name' => $tvname));
 return $tv->get('caption');
}


Conclusion
Err. tvname=tv_fistashka

How so?
July 9th 19 at 10:59
1 answer
July 9th 19 at 11:01
Solution
===
or
if ($tvname==") {
php.net/manual/ru/language.operators.comparison.php
php.net/manual/ru/types.comparisons.php
We strongly advise you to read, understand and learn all that here!
Well, it's cap. But as triggered $tvname == 0 if string tvname "tv_fistashka"? - camryn27 commented on July 9th 19 at 11:04
: var_dump(0 == "a"); // 0 == 0 -> true - Kyleigh_Hills commented on July 9th 19 at 11:07
: the horror. (false=='wtf') // false. It is essentially the same as (0=='wtf'). Go cry in the bushes - camryn27 commented on July 9th 19 at 11:10
: here's another PIP from the top: php.net/manual/ru/types.comparisons.php - Kyleigh_Hills commented on July 9th 19 at 11:13
: in short, it is necessary to use strict comparisons and no steam%). - camryn27 commented on July 9th 19 at 11:16
: not always better) I memorized the signs on the principle: "codici PHP first recite a comparison of types and regex" ))
need it constantly. - Kyleigh_Hills commented on July 9th 19 at 11:19
:
>>> what horror. (false=='wtf') // false. It is essentially the same as (0=='wtf'). Go cry in the bushes

absolutely NOT THE SAME thing and the bushes should go then, if you fail to understand how type casting in PHP

(false=='wtf') here to perform the comparison operation blaze will result to Boolean type the string "wtf", that is, converts it to TRUE, because it is not empty

(0=='wtf') - here, the string is converted to the number. Read about type conversion again. So for example if you passed the string "1wtf", you would get the comparison 0 == 1 and it would have been FALSE - Arielle commented on July 9th 19 at 11:22

Find more questions by tags PHPMODX