php命名空间更麻烦了,紧急求教PHP命名空间问题,12:10了我还没有吃饭呢,各位帮忙!!...

各位好,我在程序中用到了websocket功能,程序本机调试没有报错,但是传到服务就报错了,在网上找了下,说是PHP版一本http://s.yanghao.org/program/viewdetail.php?i=140457

我机器上的PHP版本是5.4的,服务器上的是5.2的,请问PHP5.2中有没有方便取代php5.3的命名空间功能,非常急!

require("lib/SplClassLoader.php");

$classLoader = new SplClassLoader("WebSocket","/lib");

$classLoader->register();

$server = new \WebSocket\Server("124.172.243.71", 8000, false);//这里报错

报错的内容如下

Unexpected character in input: '\' (ASCII=92) state=1 in

回复讨论(解决方案)

PHP 在 5.3.0 以后的版本开始支持命名空间。

所以说 你还是乖乖的升级服务器吧

SplClassLoader.php的代码如下,我应该如何改,请各位帮忙!升级服务器非常麻烦,因为服务器还有网站在运行,我没有十分把握,风险太大了,要是网站跑不来起来,那问题就更大了

SplClassLoader that loads classes of the

* specified namespace.

*

* @param string $ns The namespace to use.

*/

public function __construct($ns = null, $includePath = null)

{

$this->_namespace = $ns;

$this->_includePath = $includePath;

}

/**

* Sets the namespace separator used by classes in the namespace of this class loader.

*

* @param string $sep The separator to use.

*/

public function setNamespaceSeparator($sep)

{

$this->_namespaceSeparator = $sep;

}

/**

* Gets the namespace seperator used by classes in the namespace of this class loader.

*

* @Return void

*/

public function getNamespaceSeparator()

{

return $this->_namespaceSeparator;

}

/**

* Sets the base include path for all class files in the namespace of this class loader.

*

* @param string $includePath

*/

public function setIncludePath($includePath)

{

$this->_includePath = $includePath;

}

/**

* Gets the base include path for all class files in the namespace of this class loader.

*

* @return string $includePath

*/

public function getIncludePath()

{

return $this->_includePath;

}

/**

* Sets the file extension of class files in the namespace of this class loader.

*

* @param string $fileExtension

*/

public function setFileExtension($fileExtension)

{

$this->_fileExtension = $fileExtension;

}

/**

* Gets the file extension of class files in the namespace of this class loader.

*

* @return string $fileExtension

*/

public function getFileExtension()

{

return $this->_fileExtension;

}

/**

* Installs this class loader on the SPL autoload stack.

*/

public function register()

{

spl_autoload_register(array($this, 'loadClass'));

}

/**

* Uninstalls this class loader from the SPL autoloader stack.

*/

public function unregister()

{

spl_autoload_unregister(array($this, 'loadClass'));

}

/**

* Loads the given class or interface.

*

* @param string $className The name of the class to load.

* @return void

*/

public function loadClass($className)

{

if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {

$fileName = '';

$namespace = '';

if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {

$namespace = substr($className, 0, $lastNsPos);

$className = substr($className, $lastNsPos + 1);

$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;

}

$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;

require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;

}

}

}

M,不了解命名空间

搞定了,升级了服务器的PHP版本,升级到5.3就没有问题了

你sb吗,之前说升级怕网站挂掉,现在又升级了,你好像把简单问题复杂化了

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值