Defined () ordefine (); what does it mean?

Source: Internet
Author: User
How can I define it without definition? Is it similar to ifdefine in C ?? It would be nice to find it in the PHP manual .. For example: defined (& #039; THINK_PATH & #039;) ordefine (& #039; THINK_PATH & #039;, dirname (_ FILE __). & #039; & #039;); how can I define it without definition?
Is it similar to if define in C ??
It would be nice to find it in the PHP manual ..
For example:
defined('THINK_PATH') or define('THINK_PATH', dirname(__FILE__).'/');

Reply content:

How can I define it without definition?
Is it similar to if define in C ??
It would be nice to find it in the PHP manual ..
For example:
defined('THINK_PATH') or define('THINK_PATH', dirname(__FILE__).'/');

The knowledge point here is also a "Short Circuit evaluation"

PHP, C, or many modern languages have this feature. When calculating the logic or expression, if the left side is true, the right side is not calculated, and true is returned directly.A or B;Can achieveif(!A) B;Effect

Similarly, if the left side of the calculation logic is false, a short circuit will also occur. If the right side is not calculated, false will be returned directly.A and B;Similarif(A) B;

The short-circuit value is close to English in terms of semantics, and avoids the visual pollution caused by "if must be curly braces (?), So it's a good practice (although strictly speaking, it's not a good habit)

Http://php.net/manual/zh/function.defined.php
Http://php.net/manual/zh/function.define.php

= W = some... defined () in the manual checks whether the name of a constant exists. If it has been defined to return true, undefined, false is returned.

Defined ('Think _ path') or define ('Think _ path', dirname (FILE).'/');

First, check whether the constant THINK_PATH is defined. If not, define a constant THINK_PATH value dirname (FILE).'/'

Similar to if (! A) The {B} statement, but written as A or B, is more brief. If THINK_PATH is defined, the condition is true and will not be followed, if THINK_PATH is not defined, the following statement is left.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.