$ _REQUEST is not created when using variable variables?

Consider the following code snippets:

Figure A:

$_REQUEST = json_decode(stripslashes(json_encode($_REQUEST, JSON_HEX_APOS)), true);

Figure B:

${'_REQUEST'} = json_decode(stripslashes(json_encode(${'_REQUEST'}, JSON_HEX_APOS)), true);

Illustration C:

${'_' . 'REQUEST'} = json_decode(stripslashes(json_encode(${'_' . 'REQUEST'}, JSON_HEX_APOS)), true);

Both demonstrate A and B work fine, demonstrate C , but they display a very strange error message:

Note: Undefined variable: _REQUEST

What's even weirder is that this only happens with a supervalve $_REQUESTif I try it with $_GET, $_POSTor $_COOKIE, all experiments work fine without raising error notifications.

I assume this is a PHP error? I work for PHP 5.3.0.

+3
source share
4 answers

( PHP 5.3.1)

, :

<?php
var_dump(${'_' . 'REQUEST'});

Undefined variable: _REQUEST


:

<?php
var_dump($_REQUEST);
var_dump(${'_' . 'REQUEST'});

.


, auto_globals_jit, $_REQUEST, , . :

SERVER ENV , , , .

, , , auto_globals_jit $_REQUEST...


, , auto_globals_jit php.ini:

; When enabled, the SERVER and ENV variables are created when they're first
; used (Just In Time) instead of when the script starts. If these variables
; are not used within a script, having this directive on will result in a
; performance gain. The PHP directives register_globals, register_long_arrays,
; and register_argc_argv must be disabled for this directive to have any affect.
; http://www.php.net/manual/en/ini.core.php#ini.auto-globals-jit
auto_globals_jit = Off

:

<?php

var_dump(${'_' . 'REQUEST'});

, .

, , auto_globals_jit $_REQUEST - .

+7

, PHP Superglobal . $this , .

http://www.php.net/manual/en/language.variables.variable.php

:

SERVER ENV , , , .

Pascal.

auto_globals_jit.

+2

, $_GET .. php bugtrack: http://bugs.php.net/

, .


Zend Studio:

<?php
var_dump( ${'_' . 'REQUEST'});
var_dump( ${'_REQUEST'});
var_dump( $_REQUEST);

, , PHP 5.2.10. , :

$foo = '_' . 'REQUEST'
$$foo //<-- is the same as $_REQUEST

EDIT: Woops, Superglobals, - Cacha102

0

"bug" . tony2001 @php, :

: .

, , $_REQUEST, GPC , - ?

0

Source: https://habr.com/ru/post/1728747/


All Articles