We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Two different servers treating very simple conditional differently?

Development and Programming

Mike's avatar
Mike
7 posts
6 years ago
Mike's avatar Mike

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.

       
James Mathias's avatar
James Mathias
225 posts
6 years ago
James Mathias's avatar James Mathias

Hi Mike,

Sorry for the trouble, it looks like you are using a third party add-on gwcode_categories. Have you reached out to them to see if they have any known issues with their add-on that could be causing this issue?

       
Mike's avatar
Mike
7 posts
6 years ago
Mike's avatar Mike

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 😊

       
Derek Jones's avatar
Derek Jones
7,561 posts
6 years ago
Derek Jones's avatar Derek Jones

What do you get if just above that conditional you add:

*{parent_id}* *{last_segment_category_id}*

The asterisks help catch any oddities like whitespace or booleans.

       
Mike's avatar
Mike
7 posts
6 years ago
Mike's avatar Mike

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?

       
Derek Jones's avatar
Derek Jones
7,561 posts
6 years ago
Derek Jones's avatar Derek Jones

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}
       
Mike's avatar
Mike
7 posts
6 years ago
Mike's avatar Mike

That does make sense – thank you!

Any idea if it would likely be an easy server or DB tweak to solve something like this? I’m unfortunately not sure if it’s happening elsewhere on the multi site.

       
Derek Jones's avatar
Derek Jones
7,561 posts
6 years ago
Derek Jones's avatar Derek Jones

Technically easy, yes, but does require that PHP is compiled with that support. The specific configure command is --with-pdo-mysql=mysqlnd. You should be able to ask your host to enable PDO with mysqlnd, and they should know what to do.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.