Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向NuSoap注册命名空间PHP类方法_Php_Soap_Autoload_Nusoap - Fatal编程技术网

向NuSoap注册命名空间PHP类方法

向NuSoap注册命名空间PHP类方法,php,soap,autoload,nusoap,Php,Soap,Autoload,Nusoap,可以在NuSoap库中注册PHP自动加载的命名空间类方法吗?需要说明的是,PHP类是命名空间的。这不是关于XML名称空间的问题 例如,如果我在某个文件中定义了一个类: <?php namespace \My\Fancy\Namespace; class MyClass { public static function foo() { /* ... */ } // ... } 在nusoap\u服务器上类中,在调用\u方法方法中,代码不允许使用名

可以在NuSoap库中注册PHP自动加载的命名空间类方法吗?需要说明的是,PHP类是命名空间的。这不是关于XML名称空间的问题

例如,如果我在某个文件中定义了一个类:

<?php

  namespace \My\Fancy\Namespace;

  class MyClass {
       public static function foo() { /* ... */ }
       // ...
  }

nusoap\u服务器上类中,在调用\u方法方法中,代码不允许使用名称空间

function invoke_method() {
    // many lines of code...

    $class = '';
    $method = '';
    if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
        $try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
        if (class_exists($try_class)) {
            // get the class and method name
            $class = $try_class;
            $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
            $this->debug("in invoke_method, class=$class method=$method delim=$delim");
        } else {
            $this->debug("in invoke_method, class=$try_class not found");
        }
    } else {
        $try_class = '';
        $this->debug("in invoke_method, no class to try");
    }

    // many lines of code...
}
但是感谢上帝的开源,让我们修改代码吧
这就是你可以做的:

function invoke_method() {
    // many lines of code...

    $class = '';
    $method = '';
    if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
        $try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
        if (class_exists($try_class)) {
            // get the class and method name
            $class = $try_class;
            $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
            $this->debug("in invoke_method, class=$class method=$method delim=$delim");
        } else {
            $this->debug("in invoke_method, class=$try_class not found");
        }
    } elseif (strlen($delim) > 0 && substr_count($this->methodname, $delim) > 1) {
        $split = explode($delim, $this->methodname);
        $method = array_pop($split);
        $class = implode('\\', $split);
    } else {
        $try_class = '';
        $this->debug("in invoke_method, no class to try");
    }

    // many lines of code...
}
解释:

// Example of namespaced class
// $this->methodname = 'Namespace.Namespace2.Class.MethodName';

// Has delimiter "." or ".." more than one time.
if (strlen($delim) > 0 && substr_count($this->methodname, $delim) > 1) {
    // code below
}

// Transform in array
$split = explode($delim, $this->methodname);
// $split = array('Namespace', 'Namespace2', 'Class', 'MethodName')

// Get the last item (method name) and remove from array.
$method = array_pop($split);
// $method = 'MethodName'
// $split = array('Namespace', 'Namespace2', 'Class')

// Transform the class name
$class = implode('\\', $split);
// $class = 'Namespace\Namespace2\Class'
通过这个简单的修改,您可以使PHP名称空间功能正常工作。

我知道很长一段时间过去了,但我希望能帮助一些人回答这个问题。

@Alex,我不相信这是重复的,因为这个问题涉及的是soap/XML名称空间,而不是PHP名称空间。我也在为同样的问题寻找解决方案!!该死当我在谷歌搜索上收到你的问题时,我很高兴,并希望它能解决我的问题:-/@jpheldson找到了解决办法吗?@RafiqueMohammed,很遗憾,我从来没有为这个问题找到过答案。祝你好运。在堆栈溢出中可能会问类似的问题。
// Example of namespaced class
// $this->methodname = 'Namespace.Namespace2.Class.MethodName';

// Has delimiter "." or ".." more than one time.
if (strlen($delim) > 0 && substr_count($this->methodname, $delim) > 1) {
    // code below
}

// Transform in array
$split = explode($delim, $this->methodname);
// $split = array('Namespace', 'Namespace2', 'Class', 'MethodName')

// Get the last item (method name) and remove from array.
$method = array_pop($split);
// $method = 'MethodName'
// $split = array('Namespace', 'Namespace2', 'Class')

// Transform the class name
$class = implode('\\', $split);
// $class = 'Namespace\Namespace2\Class'