What is the general definition of constants

Source: Internet
Author: User
Tags echo d
What is the general definition of constants?

Novice questions,
Is the value of a constant and a variable the same as in memory and is there a stack area?
Why is there a constant such thing? Anyway it is stored value, directly with the variable instead of it soon good.

What are the typical situations where constants and variables are used?


------Solution--------------------
Look at the name should know some, one can be modified, a cannot be modified
------Solution--------------------
The key is that the constants are global
------Solution--------------------
This post was last edited by xuzuning on 2012-12-13 13:39:17

References:
Moderator variables can also be global
Is it? You can use it.
$a = 123;
Define (' A ', 123);

function Func1 () {
echo $a; notice:undefined variable:a
}
function Func2 () {
Echo A; 123
}

Func1 ();
Func2 ();

------Solution--------------------
Citation:
This post was last edited by xuzuning on 2012-12-13 13:39:17
Reference: Moderator variables can also be global yes Yes? You can use it. php code?123456789101112$a = 123;define (' A ', 123); function Func1 () {echo $a;//not
...
He probably meant to declare it as global
------Solution--------------------
Gather up the excitement.

$GLOBALS [' A ']= ' AA ';
Function abc () {
echo $GLOBALS [' a '];
}
ABC ();

------Solution--------------------
Continue to fight the sauce oil

Define (' D ', ' DD ');
$b = ' BBB ';
$GLOBALS [' A ']= ' AA ';
Function abc () {
Global $b;//If you do not join this line, the bottom line must be wrong, this is the scope of the variable.
Echo $b;
echo $GLOBALS [' a '];
Echo D;

$c = ' CCC ';
}
ABC ();
Echo D;
Echo $c;//This line must be wrong, because the $c is in function

------Solution--------------------
The structure definition of a constant:
typedef struct _ZEND_CONSTANT {
Zval value of value;//constant

------Solution--------------------

------Solution--------------------
Const_ct_subst (Allow compile-time overrides)
Char *name;//constant Name
UINT name_len;//Name length
The int module_number;//constant module number, which is initialized by a user-defined constant to Php_user_constant
} zend_constant;




Structure definition of a variable
struct _zval_struct {
/* Variable Information */
Zvalue_value value;//Variable Value
Zend_uint refcount__gc; Reference count, the GC determines whether to reclaim memory based on this value
Zend_uchar type;//Variable Type
Zend_uchar is_ref__gc; Whether it is a reference
};



  • 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.