What is the use of "defined (" YII_DEBUG ") or" in "defined (" YII_DEBUG ") or define (" YII_DEBUG ", false);"?

In the line of code, defined('YII_DEBUG') or define('YII_DEBUG', false);we check whether debug has been previously defined, it will not do anything, but if it is not installed false.

I did not understand what this means that if we want to redefine the previous value and why we cannot just do it define('YII_DEBUG', false);, why is it necessary to check the previous value if we do not want to use it?

+4
source share
5 answers

I did not do this, but you did not quite understand my question, we can change the value of YII_DEBUG in /web/index.php. one more thing if YII_DEBUG defined elsewhere, but after that, if we want to change its value, what to do as “or” will not change it, and is it too constant to change its value?


Yes, you are very mistaken ... You can declare the value YII_DEBUG anywhere, but ... if it is overridden: Note. The constant YII_DEBUG is already defined in ... I think the reason is certain () or ... TO PREVENT THIS ERROR

+1
source

<?php
  defined('YII_DEBUG') or define('YII_DEBUG', true);
  defined('YII_ENV') or define('YII_ENV', 'dev');

defined in yourApp/web/index.php

. true, , , .

, costant false. .

- , , , php . . php doc http://php.net/manual/en/function.defined.php defined — Checks whether a given named constant exists

Yii2 http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html

+1

YII_DEBUG. YII_DEBUG ( ), , . YII_DEBUG , , .

YII_DEBUG YiiBase.php yii.php

+1

true false " ", :

define('YII_DEBUG', true);

defined('YII_DEBUG') or define('YII_DEBUG', false);, YII_DEBUG true false, , YII_DEBUG true false - , 't or.

defined('YII_DEBUG') or define('YII_DEBUG', true);

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

, , , YII_DEBUG - , , true.

Edit:

, :

if (isset($_GET['debug'])) define('YII_DEBUG', true);

, URL-, :

www.example.com/site/myAction www.example.com/site/myAction/debug/true index.php

2:

YII_DEBUG index.php, Yii, yii.php Yii2, Yii1 - framework/YiiBase.php

+1
source

defined('YII_DEBUG') or define('YII_DEBUG', false)checks if a constant has been defined YII_DEBUG(regardless of its value), and if it has not been previously defined, it defines the constant as false.

The string ensures that the constant is defined so that it can be used, and its first part ( defined('YII_DEBUG') or) ensures that this string does not override it until falseif it was previously set to true.

+1
source

Source: https://habr.com/ru/post/1614726/


All Articles