Script Expressions and Strict Comparisons

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
ben.bunk's picture

When working with a script expression, strict comparisons might not work exactly like you would expect. For example, when strictly comparing for a TRUE value this will likely fail:

<?php
%input === TRUE
?>

Here is an example where I stumbled onto this:

<?php
function _multifactor_validate_pin($pin = NULL) {
  return
TRUE;
}
$script->addSet('success', '^_multifactor_validate_pin(%pin)');
$script->addGotoIf('success_message', '^%success === TRUE');
?>

Unfortunately, the above addGotoIf will always evaluate to FALSE. The callback returns TRUE but the result is type juggled into a numeric '1' somewhere along the way. Either of the following examples is a viable replacement.

<?php

$script
->addGotoIf('success_message', '^%success == TRUE');
?>

<?php
$script
->addGotoIf('success_message', '^%success === 1');
?>

VoIP Drupal

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: