Why is this always evaluating to false?

I have a piece of code I made

abstract class WorkTypes
{
    const Portfolio = 0;
    const Study = 1;
}

function get_our_work ( $atts )
{

   // see https://codex.wordpress.org/Shortcode_API

    $work_type = (strcmp($atts['workType'],'ports') === 0) ?  WorkTypes::Portfolio : WorkTypes::Study;

    include "page-content/our_work.php";
}

and for reason $work_type is always evaluating to be WorkTypes::Study even when I’m 100% sure that $atts['workType'] is equal to 'ports'. So I know that (strcmp($atts['workType'],'ports') === 0) is always evaluating to false. Why?

Related posts

1 comment

  1. you’re doing a boolean evaluation on a number? I haven’t done php in quite a while but I’m pretty sure you have to have something like:

    $work_type = (strcmp($atts[‘workType’],’ports’) <> 0) ? WorkTypes::Study : WorkTypes::Portfolio;

    Which reads, if your $atts[‘workType’] does not match ‘ports’ then WorkTypes::Study else it does match so use WorkTypes::Portfolio regardless of which comparison string is different.

Comments are closed.