I purchased a Drupal theme and the the support is...lacking. So I thought I'd try and tackle it myself. I'm relatively new to PHP programming, so please take it easy on me :)
The error I got was: Notice: Object of class Drupal\Core\Field\FieldItemList could not be converted to int in theme_css_alter()
Digging into the error, it came from the first line of code in this if statement:
if(isset($node->nid) && $node->nid == 90){
//do stuff
}
I did my research and found that its a PHP error when using the == operator, likely since $node->nid is being fetched as a string, and 90 is an integer, and it can't convert the nid on the fly.
Possible solutions I found while Googling were either making a 'getter' to fetch the nid as an integer (which sounds more complicated than necessary), using the === operator; and I'm guessing on my own that if I convert 90 to a string it would also work?
Now, doing a test run, === does stop the error from showing, but my research shows that === only works when both the value and type are equal, and given I'm comparing a string and an integer, I assume that it would always just be false then.
So...
- Am I correct in saying that in PHP 90 (as a string) does not == 90 (as an integer)?
- Am I correct in saying that using === instead of == is NOT the correct way to compare a string and integer?
- Would $node->nid == (string)90{ be the correct way to compare for this if statement? What is the most correct way to do this comparison?