K
K
Koal Koalich2018-02-28 15:17:14
PHP
Koal Koalich, 2018-02-28 15:17:14

Where can I find a description of such a logical expression?

Gutted with Yii2 guides. The input script says: You can guess that this is equivalent to this:
defined('YII_DEBUG') or define('YII_DEBUG', true);

if (!defined('YII_DEBUG'))
{
    define('YII_DEBUG', true);
}

But! Something I can't find the OFFICIAL description on php.net of such constructions. Can this be considered bad manners because it confuses? How, for example, then to interpret foo() and bar()? xhor?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Soshnikov, 2018-02-28
@artem90

This is all about logical operators:
php.net/manual/ru/language.operators.logical.php
In case of OR, the first expression is executed first and only if it is false, the second one is executed (what is the point of ORing the second expression if the first one is already true?)
for AND will be similar to foo() && bar()
bar() will only be executed if foo() === true
Regarding readability:
1 - it all depends on the context. If it's not clear to the author that it's easy to read, then it's not easy to read
2 - Yii has a very peculiar code style and you shouldn't take an example from them)
3 - [additional] check whether the constant is set or not - it's really bad.. A constant is a constant to be constant. If it exists, then it doesn’t - then it’s a variable, and a bad one =D

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question