Weird PHP behavior if I put exclamation point into variable name

前端 未结 2 1859
北海茫月
北海茫月 2021-01-19 12:21

I have weirdest problem with PHP itself, that I\'ve ever seen.

Setup:

PHP 5.33, (tried PHP 5.2.14 as well) under IIS

Problem

2条回答
  •  悲&欢浪女
    2021-01-19 12:47

    well what is your question about? what is the reason of this error or how to avoid it?
    A first one is probably because of some odd PHP internals. For example, you cannot use numeric keys with same consequences.
    A latter one is even simpler - do not put exclamation point into a key in session array.

    As I recall, PHP sessions mechanism came up from the PHPLib - a first PHP framework ever. Written by some volunteer students. Not a very optimal one. Once added to PHP in the version 4.0, become usable only at 4.1 but still with some odd legacy, like register_globals support. The latter one is most likely the reason of your problem. $_SESSION array key must be valid PHP variable name, in sake of that ancient register_globals behavior where session variables become global PHP variables.

提交回复
热议问题