What kind of coding Nomenclature is this? It doesn't seems to be ternary also

  $list_id = 0;
  if( isset($args['id']) ) $list_id = (int)$args['id'];

If part doesn’t even have a ternary operation condition nor even : what kind of coding practice is this? I have seen this first time. Is there any nomenclature for such usage in PHP?

It’s just a common-or-garden if statement.

It could be written:

if( isset($args['id']) ) {
  $list_id = (int)$args['id'];

Or, since PHP 7: $list_id = (int)$args['id'] ?? 0; (this is called the Null Coalescing Operator)


int stands for integer. why bare we using int here? ids will be integers not float by their designated virtues.

I prefer using PHP alternative syntax because to me it is far easier to understand rather than trying to match curly braces:



  $list_id = 0;
  if( isset($args['id']) ) : // notice the trailing colon
     $list_id = (int)$args['id'];
  elseif(FALSE) :
    // echo 'FALSE';
  elseif(TRUE) :
    // echo 'TRUE and NOT FALSE';
    // echo 'ALL ELSE FAILED';

It’s your code, you tell me :stuck_out_tongue:
Presumably $args comes in as an array of strings, rather than int.

Usually, this sort of thing can be ignored, as PHP does implicit conversions to int when it needs to do math on a string, but some people will say that you should explicitly convert and store as an int. shrug

1 Like

Not my code I was following a WP plugin development series on udemy - The series seems to be 6 years old its there code.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.