Hello,
Recently, I created a staging environment for a multi site by cloning a prod enviorment. These two environments are on different servers and thus have different server configurations:
New Server (Staging): PHP Version 7.3.2 ICU version 4.2.1 ICU TZData version 2009j ICU Unicode version 5.1
Old Server (Prod): PHP Version 5.5.38 version 1.1.0 (no label, but is listed under “ICU”) ICU version 4.2.1
Now, for whatever reason, staging is handling this piece of code differently than prod:
{if segment_2 == ""}
<div>
<div></div>
{exp:gwcode_categories group_id="2" style="linear" site_id="1"}
{if parent_id == last_segment_category_id}
<div>content would go here</div>
{/if}
{/exp:gwcode_categories}
</div>
{/if}
Specifically, this piece:
{if parent_id == last_segment_category_id}
Whenever last_segment_category_id is a 0, parent_id acts as if they’re identical. Any idea what could be occurring to cause this to happen on the newer server? I tried matching PHP versions, but unfortunately that didn’t solve it.
Thank you for the reply!
I haven’t reached out to the gwcode dev, as I’m actually not sure if this is a gwcode issue necessarily.
The two variables (parent_id and last_segment_category_id) are acting as if equal whenever last_segment_category_id is a 0. A sample situation where this happens is when values are as so:
parent_id = 2
last_segment_category_id = 0
2 is not equal to 0 though, yet the following still acts as if it’s true:
{if parent_id == last_segment_category_id}
To fix this, I could probably add another conditional (last_segment_category_id != 0), but I’d love to be able to just figure out what’s going on rather than code around it 😊
Thank you for the asterisk suggestion! I feel pretty silly now, but the “2” value from my previous post was actually from a comment (“test 2”). Guess I kept the 2.
Now it’s wayyy more clear what’s happening:
*0* **
When this combination happens, it results in the below statement being true:
{if parent_id == last_segment_category_id}
Oddly enough, this doesn’t result in a true statement on the prod server, just the staging server.
So I guess the question now is why does 0 == “” on one server, but not the other?
Ok now it makes sense! I’m guessing one server has PDO configured to use the mysqlnd native driver, and the other does not. On the one that does not, database results are all stringafied, and you lose real integers. So on one server you are comparing 0
to ''
and on the other '0'
to ''
. Since zero as a string could mean content, ExpressionEngine does not treat a string zero as FALSE. See this table for details.
mysqlnd is recommended for performance and accuracy, but the plugin could also handle this by making sure its variables were typed properly, or a variation like you suggested could just be:
{if last_segment_category_id && last_segment_category_id == parent_id}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.