language-construct

?: operator (the 'Elvis operator') in PHP

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 15:41:42
I saw this today in some PHP code: $items = $items ?: $this->_handle->result('next', $this->_result, $this); I'm not familiar with the ?: operator being used here. It looks like a ternary operator, but the expression to evaluate to if the predicate is true has been omitted. What does it mean? BalusC It evaluates to the left operand if the left operand is truthy , and the right operand otherwise. In pseudocode, foo = bar ?: baz; roughly resolves to foo = bar ? bar : baz; or if (bar) { foo = bar; } else { foo = baz; } with the difference that bar will only be evaluated once. You can also use

What is the difference between a language construct and a “built-in” function in PHP?

﹥>﹥吖頭↗ 提交于 2019-11-26 10:06:01
I know that include , isset , require , print , echo , and some others are not functions but language constructs. Some of these language constructs need parentheses, others don't. require 'file.php'; isset($x); Some have a return value, others do not. print 'foo'; //1 echo 'foo'; //no return value So what is the internal difference between a language construct and a built-in function? (This is longer than I intended; please bear with me.) Most languages are made up of something called a "syntax": the language is comprised of several well-defined keywords, and the complete range of expressions

Difference between period and comma when concatenating with echo versus return?

混江龙づ霸主 提交于 2019-11-26 06:03:03
问题 I just found that this will work: echo $value , \" continue\"; but this does not: return $value , \" continue\"; While \".\" works in both. What is the difference between a period and a comma here? 回答1: return does only allow one single expression. But echo allows a list of expressions where each expression is separated by a comma. But note that since echo is not a function but a special language construct, wrapping the expression list in parenthesis is illegal. 回答2: You also have to note

What is ?: in PHP 5.3? [duplicate]

老子叫甜甜 提交于 2019-11-26 04:41:45
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What are the PHP operators “?” and “:” called and what do they do? From http://twitto.org/ <?PHP require __DIR__.\'/c.php\'; if (!is_callable($c = @$_GET[\'c\'] ?: function() { echo \'Woah!\'; })) throw new Exception(\'Error\'); $c(); ?> Twitto uses several new features available as of PHP 5.3: The DIR constant The ?: operator Anonymous functions What does number 2 do with the ?: in PHP 5.3? Also, what do they

?: operator (the &#39;Elvis operator&#39;) in PHP

蓝咒 提交于 2019-11-26 04:32:22
问题 I saw this today in some PHP code: $items = $items ?: $this->_handle->result(\'next\', $this->_result, $this); I\'m not familiar with the ?: operator being used here. It looks like a ternary operator, but the expression to evaluate to if the predicate is true has been omitted. What does it mean? 回答1: It evaluates to the left operand if the left operand is truthy, and the right operand otherwise. In pseudocode, foo = bar ?: baz; roughly resolves to foo = bar ? bar : baz; or if (bar) { foo =

What is the difference between a language construct and a “built-in” function in PHP?

北慕城南 提交于 2019-11-26 01:56:38
问题 I know that include , isset , require , print , echo , and some others are not functions but language constructs. Some of these language constructs need parentheses, others don\'t. require \'file.php\'; isset($x); Some have a return value, others do not. print \'foo\'; //1 echo \'foo\'; //no return value So what is the internal difference between a language construct and a built-in function? 回答1: (This is longer than I intended; please bear with me.) Most languages are made up of something