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

jxdyzwh 2013-01-14 12:14:52
各位好,我在程序中用到了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
...全文
344 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2013-01-14
  • 打赏
  • 举报
回复
PHP5.2中没有命名空间 你可以删去有关“命名空间”的声明部分 退化成普通的类和函数
jxdyzwh 2013-01-14
  • 打赏
  • 举报
回复
没看看明白 ,郁闷呀
ImN1 2013-01-14
  • 打赏
  • 举报
回复
手册上的一段回复 -------------------------------------------------------------------------------------- a dot schaffhirt at sedna-soft dot de02-Feb-2010 06:24 Just in case you wonder what the practical use of the namespace keyword is... It can explicitly refer to classes from the current namespace regardless of possibly "use"d classes with the same name from other namespaces. However, this does not apply for functions. Example: <?php namespace foo; class Xyz {} function abc () {} ?> <?php namespace bar; class Xyz {} function abc () {} ?> <?php namespace bar; use foo|Xyz; use foo|abc; new Xyz(); // instantiates \foo\Xyz new namespace|Xyz(); // instantiates \bar\Xyz abc(); // invokes \bar\abc regardless of the second use statement |foo|abc(); // it has to be invoked using the fully qualified name ?> (Sorry, I had to use "|" instead of "\", as it was always discarded in the preview, except within a comment.) Hope, this can save someone from some trouble. Best regards. ----------------------------------------------------------------------------
jxdyzwh 2013-01-14
  • 打赏
  • 举报
回复
把服务器的PHP版本升级么3.0以上就没有问题了,服务器的版本与开发机器的版本不一样,感觉很麻烦,各位以后在开发的过程中要注意下
jxdyzwh 2013-01-14
  • 打赏
  • 举报
回复
SplClassLoader.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; } } }

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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