3

In a template I was working on recently, I started to get PHP Notices about undefined constants FALSEOR and FALFALSEORFALSE:

A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant FALSEOR - assumed 'FALSEOR'
Filename: libraries/Functions.php(683) : eval()'d code
Line Number: 205

[and]

A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant FALFALSEEORFALSE - assumed 'FALFALSEEORFALSE'
Filename: libraries/Functions.php(683) : eval()'d code
Line Number: 260

The template code that generated these messages was:

{if STYLE}
    <tr>
        <td>Style</td>
        <td>{STYLE}</td>
    </tr>
{/if}

{if YEARBUILT}
    <tr>
        <td>Year Built</td>
        <td>{YEARBUILT} {if YEARBUILTSRC}({YEARBUILTSRC}){/if}</td>
    </tr>
{/if}

The variable names in all caps are variables provided by a plug-in. It is possible that they may have empty values, but I haven't been able to produce a case where any would be undefined [in the array consumed by TMPL->parse_variables() in the plugin].

I'm stumped as to why they're being parsed as PHP constants... And even so, I don't see where the strings 'FALSEOR' or 'FALFALSEORFALSE' are being created. Those strings don't appear anywhere in the EE source [that I can find], and none of the template variables are so named.

Should I report this as a bug? Has anybody seen something like this before?

6
  • 1
    Without the plugin code, it is very difficult to debug this. Also, the error says line 205, yet your example only has a few lines. If you look at the other line for the error (functions.php line 683) it is the eval() function. Maybe you're generating some PHP that fails?
    – GDmac
    Commented Dec 27, 2012 at 11:09
  • 2
    In the past I have resolved a similar error by using {if STYLE != ''} instead of just {if STYLE}. Whilst I believe that both should be valid, I have experienced this same problem. Simply adding != '' solved it for me. Let me know if this helps.
    – Lea Hayes
    Commented Dec 27, 2012 at 13:02
  • Yes, please post the code for the plugin that's generating these variables (or a link to that code). It is surely the culprit. Commented Dec 27, 2012 at 13:39
  • Michael, did you ever resolve this? If yes, can you post your fix? Did Lea's above suggestion of {if STYLE != ''} help?
    – Anna_MediaGirl
    Commented Jan 17, 2013 at 2:56
  • This is note quite resolved, but unfortunately I'm not able to share the code of the plugin at the moment. I can't reproduce the issue consistently enough to judge whether {if STYLE != ''} is a solid fix, but it certainly doesn't hurt. Really, I'm mostly curious where FALSEOR or FALFALSEEORFALSE are coming from, as I can't find them in the code, and they're definitely not in the plug-in's data array. Commented Jan 21, 2013 at 22:34

1 Answer 1

1

PHP has four values when it evaluates an if condition, true, truthy, false, and falsey.

http://www.phabricator.com/docs/phabricator/article/PHP_Pitfalls.html

Depending on what you're getting back from your add-on, or the add-on's datasource (especially if the data from the source is inconsistent) PHP's conditional logic may act strange if you don't check the value explicitly (ex: STYLE != '').

Also since it sounds like you'll be checking for empty strings. I might take an additional step and fashion your IF statements like this:

{if "{STYLE}" != ""}
   ...
{/if}

This will ensure that "STYLE" is always interpreted as a string rather than being evaluated as an object or PHP reserved value

2
  • Patrick, I suspect you're very much on the case here. The Pitfalls page is great, and would explain what might be happening within the code. The tip to quote the if-argument is likely what will clear this, and let's hope it does ;) Commented Feb 19, 2013 at 20:07
  • So far, explicitly checking the string value is working. Thanks for the additional info/link Patrick! Commented Feb 21, 2013 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.