Ternary operators and variable reassignment in PHP

Posted by TomcatExodus on Stack Overflow See other posts from Stack Overflow or by TomcatExodus
Published on 2011-01-09T20:46:37Z Indexed on 2011/01/09 20:53 UTC
Read the original article Hit count: 199

Filed under:
|

I've perused the questions on ternary operators vs. if/else structures, and while I understand that under normal circumstances there is no performance loss/gain in using ternary operators over if/else structures, I've not seen any mention of this situation. Language specific to PHP (but any language agnostic details are welcome) does the interpreter reassign values in situations like this:

$foo = 'bar'
$foo = strlen($foo) > 3 ? substr($foo, 0, 3) : $foo;

Since this would evaluate to $foo = $foo; is this inefficient, or does the interpreter simply overlook/discard this evaluation?

On a side note, what about:

!defined('SECURE') ? exit : null;

© Stack Overflow or respective owner

Related posts about php

Related posts about ternary-operator