2024 年 PHP 日本研討會

SoapServer::addFunction

(PHP 5, PHP 7, PHP 8)

SoapServer::addFunction新增一個或多個函式來處理 SOAP 請求

說明

公開 SoapServer::addFunction(陣列|字串|整數 $functions):

將一個或多個函式匯出給遠端用戶端

參數

functions

要匯出單一函式,請將函式名稱以字串形式傳遞給此參數。

要匯出多個函式,請傳遞一個函式名稱的陣列。

要匯出所有函式,請傳遞特殊常數 SOAP_FUNCTIONS_ALL

注意事項:

functions 必須以與 WSDL 檔案中定義相同的順序接收所有輸入參數(它們不應接收任何輸出參數作為參數),並返回一個或多個值。要返回多個值,它們必須返回一個具有命名輸出參數的陣列。

返回值

不返回任何值。

範例

範例 #1 SoapServer::addFunction() 範例

<?php

function echoString($inputString)
{
return
$inputString;
}

$server->addFunction("echoString");

function
echoTwoStrings($inputString1, $inputString2)
{
return array(
"outputString1" => $inputString1,
"outputString2" => $inputString2);
}
$server->addFunction(array("echoString", "echoTwoStrings"));

$server->addFunction(SOAP_FUNCTIONS_ALL);

?>

參見

新增註記

使用者貢獻的註記 1 則註記

11
dotpointer at gmail dot com
17 年前
使用 SOAP_FUNCTIONS_ALL 時要小心,因為它會將所有可用的 PHP 函式新增到您的伺服器。

這可能是一個潛在的安全威脅,想像一下用戶端執行以下操作

echo $client->file_get_contents("c:\\my files\\my_passwords.doc");

就這樣,他們就拿到了你的 my_passwords.doc 檔案內容。
To Top