Warning Full Text: PHPWarning: Unknown: Yourscriptpossiblyreliesonasessionside-effectwhichexisteduntilPHP4.2.3.Pleasebeadvisedthatthesessionextensi
The warning is as follows:
PHP Warning: Unknown: Your script possibly relies on a session side-effect
Which existed until PHP 4.2.3. Please be advised that the session extension does
Not consider global variables as a source of data, unless register_globals is enabled.
You can disable this functionality and this warning by setting session. bug_compat_42
Or session. bug_compat_warn to off, respectively. in Unknown on
There are many ways to solve this problem on the Internet, but I don't know the answer. what is the real reason? how can this problem be solved?
Remember this first. at PHP4.2, register_globals is set to OFF by default.
After 4.2.3, to be compatible with the previous mode, PHP introduced bug_compat_42. when this option is enabled (enabled by default), PHP will allow automatic use of the variables in the SESSION as global variables. however, if the bug_compat_warn option is enabled, this feature is reported to be used.
Let's look at a piece of code,
Session_start ();
Var_dump ($ _ SESSION );
$ Name = 'laruence ';
$ _ SESSION ['name'] = null;
?>
The above code, when bug_compat_42 is enabled and register_globals is disabled, refreshes the page output for the following two times:
// First time:
Array (0 ){}
// Second time
Array (1) {["a"] => string (8) "laruence "}
Why is the second time not NULL? because when bug_compat_42 is enabled, PHP considers the variable a as a reference of $ _ SESSION ['A']. when session_close, write back the value of variable.
In this process, if bug_compat_warn is enabled, a warning at the beginning of the article will be thrown.
So, that it is ~
So what conditions does it provide a warning? With these conditions, we can avoid this warning,
In PHPSRC/ext/session. c, there are all the answers we want:
Static void php_session_save_current_state (TSRMLS_D )/*{{{*/
{
Int ret = FAILURE;
IF_SESSION_VARS (){
// If a Session array exists
If (PS (bug_compat )&&! PG (register_globals )){
HashTable * ht = Z_ARRVAL_P (PS (http_session_vars ));
HashPosition pos;
Zval ** val;
Int do_warn = 0;
Zend_hash_internal_pointer_reset_ex (ht, & pos );
While (zend_hash_get_current_data_ex (ht
, (Void **) & val, & pos )! = FAILURE ){
If (Z_TYPE_PP (val) = IS_NULL) {// The variable is null.
If (migrate_global (ht, & pos TSRMLS_CC) {// variable write-back
Do_warn = 1;
}
}
Zend_hash_move_forward_ex (ht, & pos );
}
If (do_warn & PS (bug_compat_warn )){
Php_error_docref (NULL TSRMLS_CC, E_WARNING, "Your script possibly
Relies on a session side-effect which existed until PHP 4.2.3 ..........");
// Omitted later
It can be seen that if you do not enable bug_compat_42 (this feature is rarely used now, it may be confusing if you do not enable it), or if you do not start bug_compat_warn, or when register_globals is enabled, you will not see this warning.
In addition, if you enable bug_compat_42, you may encounter the following NOTICE ..
PHP Notice: Unknown: The session bug compatibility code will not try
Locate the global variable $324324 due to its numeric nature in Unknown on line 0
This is a warning when you use a digital index in $ _ SESSION.