mysql - php defined constant in if/else shorthand -
this question has answer here:
i've been working on php course, , 1 of exercises has create config.php file wherein define database constants.
i know standard way of doing this, is:
define("name", "value");
however, exercise has written differently. it's in if/else shorthand. know it's correct, because works. don't understand why works. it's simple answer more experienced devs:
defined('db_server') ? null : define('db_server', 'localhost');
the way read it, it's checking see if db_server defined. if it's true, sets null ?
why null out value of constant if it's defined?
if it's defined, runs expression null
, noop (does nothing). otherwise, runs define
. write defined('db_server') ?: define('db_server', 'localhost')
nowadays, think confusing. have written as:
if (!defined('db_server')) { define('db_server', 'localhost'); }
Comments
Post a Comment