Hey guys,

Having some difficulties understanding why my OR || operator is not working...
First part is BOOLEAN and it is working
Second part is STRING and it is working, it returns the desired value

What could it be ?

<?php if(($oferte->isOrdered($oferte->CleanSapStyleNumbers($oferta->VBELN)) == false) || ($oferte->OfertaValida($oferte->CleanSapStyleNumbers($oferta->VBELN))->valabilitate == "VALABILA")): ?>
some stuff
<?php endif; ?>

Dani AI

Generated

Short answer: the logical operator itself almost never “breaks” if each sub-expression works on its own. When || behaved differently than && in this case, the likely causes are a subtle typo (single | / invisible character), type/coercion differences, short‑circuit/side‑effects from the method calls, or a hidden warning/notice that changed runtime flow. As noted, each part worked independently, and as pointed out, that means the boolean logic is probably fine — the issue is in how the pieces are being evaluated together.

Quick checklist to diagnose and fix:

  • Turn on full error reporting to catch notices/exceptions: error_reporting(E_ALL); ini_set('display_errors', 1);
  • Avoid calling the same helper twice. Cache the cleaned key so both methods operate on the exact same value.
  • Capture each sub-expression into variables and var_dump() their values and types to see what PHP is actually comparing.
  • Prefer strict comparisons (===) to avoid surprises from type juggling.
  • Re-type the operator in the editor to ensure there are no stray/non‑ASCII characters or an accidental single pipe (|).

Example debug pattern:

$clean = $oferte->CleanSapStyleNumbers($oferta->VBELN);
$isOrdered = $oferte->isOrdered($clean);              // expect boolean
$offerObj = $oferte->OfertaValida($clean);            // expect object or null
$val = $offerObj && isset($offerObj->valabilitate) ? $offerObj->valabilitate : null;

var_dump($isOrdered, $val);

if ($isOrdered === false || $val === 'VALABILA') {
    // do the work
}

If the condition only worked after switching to &&, check for side‑effects: one method might change state that affects the other, so changing evaluation order (or forcing both evaluations by using variables) will reveal that. Storing intermediate results and using strict checks almost always makes the root cause obvious.

Recommended Answers

All 4 Replies

Does either of those statements return true or 1 or anything that is not null or false? If yes, then your || operator is working for sure :).

if i use each part separately, it works ...

Got it solved with &&

Well that's pretty weird :p. The statement should then also be triggered with || if you ask me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.