Note 018 the constant () function in PHP

Source: Internet
Author: User

Grammar

Mixed constant (string $name)

Description

The constant () function returns the value of a constant. This function is particularly useful when you do not know the name of the constant beforehand, but need to get the value of the constant.

The value of the corresponding constant is obtained by passing the name of the constant to the $name parameter.

This function still applies to class constants.

return value

Returns the value of the constant, or null if the constant is undefined, but at this point a e_warning level error is generated.

Example

  <?php    define ("MAXSIZE", +);    echo MAXSIZE;    ECHO constant ("MAXSIZE"); Same thing as the previous line    interface Bar {        Const TEST = ' foobar! ';    }    class Foo {        const TEST = ' foobar! ';    }    $const = ' test ';    Var_dump (Constant (' Bar:: '. $const)); String (7) "foobar!"    Var_dump (Constant (' foo:: '. $const)); String (7) "foobar!"

The above is the note 018 PHP constant () function content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.