[英]php autoload variable class name
誰能解釋這是如何工作的:
${(int)!${0}=$variable->other['class']}::my_static_method();
在這個stackoverflow問題的答案中:
它與以下功能相同:
${0}=$variable->other['class'];//value here lets say is 'myClass'
${0}::my_static_method();//here now is myClass::my_static_method(); called
為什么是(int)!
用過的? 因為他只是在欺騙。
print (int)!${0}=$variable->other['class'];
結果print (int)!${0}=$variable->other['class'];
是0
。
因為如果在此處設置${0}=$variable->other['class']
,
print (bool)${0}=$variable->other['class'];
會是true
。
然后它將通過否定!
,所以它變為false
,最終(int)
0
。
多數民眾贊成在那之前設置的變量的名稱: ${0}
。
但是,給全局變量一個數字是非常不好的做法。
通常,所有變量必須以_
或A-Za-z
開頭。
不知道為什么放棄它作為例子,也許是為了取笑人們。
根本不要使用它!
只是為了說明它是如何完成的;)(工作代碼)
error_reporting(0);
define(0x7F,' ..the crazy Girl');
define('§','at? ');
define('_',' Wh');
${'$#?!'} = ' Arrr!';
$♂ = Tom;
$♀ = Tina;
$c = get_defined_constants();
print _ . § . $♂ .' '. Just . ' ' . Want . ' ' . To ." ". Lov€ ." ". $♀ . $c[127] . ${'$#?!'};
//result: What? Tom Just Want To Lov€ Tina ..the crazy Girl Arrr!
隨時發瘋。 :-)
它是一個變量變量語句,使用布爾語句創建全局變量名會導致第一個${ }
${
(int)
!
${0}
$0
=
$0
變量。 $variable->other['class']
}
::
因此,按照Layman的說法,它可以創建以下語句:
$1::my_static_method();
為什么要數字? 由於變量名是由布爾值語句創建的(即true或false),因此將其取反並轉換為整數。 在PHP中, true
和false
等於1
和0
。
因此,失敗的$0
$1
,成功的$0
。
總體而言,請記住,您繞過了語法錯誤的PHP解釋器。 雖然變量變量的功能旨在創建動態變量名,但我不認為它們意味着像這樣被濫用,因此,這可能意味着您的代碼可能會在較新版本的PHP中中斷。 一個示例就是JustOnUnderMillions的答案,其中PHP 7的結果是What? Tom Just Want To Lov€ Tina Arrr!
What? Tom Just Want To Lov€ Tina Arrr!
只是說,使用可變變量語句無論如何都是不好的編程習慣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.