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

jxdyzwh 2013-01-14 12:22:42
各位好,我在程序中用到了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
...全文
342 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
初初哥 2013-08-26
  • 打赏
  • 举报
回复
你sb吗,之前说升级怕网站挂掉,现在又升级了,你好像把简单问题复杂化了
jxdyzwh 2013-01-14
  • 打赏
  • 举报
回复
搞定了,升级了服务器的PHP版本,升级到5.3就没有问题了
liuser_cn 2013-01-14
  • 打赏
  • 举报
回复
M,不了解命名空间
jxdyzwh 2013-01-14
  • 打赏
  • 举报
回复
SplClassLoader.php的代码如下,我应该如何改,请各位帮忙!升级服务器非常麻烦,因为服务器还有网站在运行,我没有十分把握,风险太大了,要是网站跑不来起来,那问题就更大了 <?php class SplClassLoader { private $_fileExtension = '.php'; private $_namespace; private $_includePath; private $_namespaceSeparator = '\\'; /** * Creates a new <tt>SplClassLoader</tt> 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; } } }
十一文 2013-01-14
  • 打赏
  • 举报
回复
PHP 在 5.3.0 以后的版本开始支持命名空间。 所以说 你还是乖乖的升级服务器吧

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧