1

how to create a dynamic function with php and call that static?

I create new soap server and register methods via an array. (too many methods) for example I create a function called me dynamically but this function only work if call that using variable's value like $SOAPACTION('sssss'); and not work for static call like me('sssss'); also I tried create_function method (that deprecated in php 7) but not working. I got the following error on call me function:

method 'me' not defined in service

Any ideas to define functions that callable by soap server?

$response = array(
    'me' => array(
        array(
            'accesskey'=>'xsd:string',
            'username'=>'xsd:string',
            'extra'=>'xsd:string',
            ,,,,,,,,
        ), 'POST'),
        ,,,,,,,,
);
if (isset($_SERVER['HTTP_SOAPACTION'])) {
    $SOAPACTION = str_replace('"','',str_replace("urn:server#","",$_SERVER['HTTP_SOAPACTION']));
    if (array_key_exists($SOAPACTION, $response)) {
        $functionName = $SOAPACTION;
        $SOAPACTION = function($name)
        {
            return array("Hello %s\r\n", $name);
        };
    }
}

$server = new soap_server;
$server->soap_defencoding = 'UTF-8';
$server->decode_utf8      = false;
$server->encode_utf8      = true;
$server->configureWSDL('APIv2');

foreach ($response as $key => $value) {
    $server->register($key, $value[0], //parameters
        array(
            'return' => 'xsd:string'
        ), //output
        'urn:server', //namespace
        'urn:server#' . $key, //soapaction
        'rpc', // style
        'encoded', // use
        $value[1]); //description
}


$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

$server->service($HTTP_RAW_POST_DATA);
scott_lotus
  • 3,171
  • 22
  • 51
  • 69
Hamid
  • 378
  • 3
  • 8

0 Answers0