2017-03-16 78 views
-1

有一個插件試圖停用我的一些PHP函數。有沒有辦法給函數名添加一個rand?PHP隨機函數名稱

這就是我想要archieve:

$rand = rand(10,100); 

function thisismyname . $rand() .() { 
    function.... 
} 
+1

爲什麼你甚至需要這個?這不是功能如何編程。而且,$ rand不是一個函數,所以()是無用的。 –

+0

@KoenHollander我知道,我想知道這是否可能。有些插件會關閉我的功能,這樣他就無法關閉它們, –

+0

我不認爲這是可能的Joost。 (只是一個不相干的問題:我們都是荷蘭人?) –

回答

2

你可以定義一個函數與一個蘭特名稱的變量,然後調用它。例:

<?php 
$function_name = mt_rand(100,10000); //rand name 
$func_{$function_name} = function(){ 
    echo 'Your function'; 
}; //variable that contains the function, named with the rand value obtained 

echo "Name: func_$function_name() =>"; 
$func_{$function_name}(); //Execute function 

此輸出:

名稱:funct_6929()=>你的功能

隨着每次運行一個diferent名稱。