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
};