I am eager to ask for a question about the PHP namespace. I haven't eaten yet at PM. please help me !!

Source: Internet
Author: User
Tags spl
I am eager to ask for a question about the PHP namespace. I haven't eaten yet at PM. please help me !! Hello everyone, I used the websocket function in the program, the local program debugging does not report an error, but the transfer to the service will report an error, found on the Internet, said PHP version of a http://s.yanghao.org/program/viewdetail.php? I = 140457.
The PHP version on my machine is 5.4 and the server is 5.2. is it convenient to replace the namespace function of php5.3 in PHP5.2!
Require ("lib/SplClassLoader. php ");
$ ClassLoader = new SplClassLoader ("WebSocket", "/lib ");
$ ClassLoader-> register ();
$ Server = new \ WebSocket \ Server ("124.172.243.71", 8000, false); // An error is returned here.
The error message is as follows:
Unexpected character in input: '\' (ASCII = 92) state = 1 in


Reply to discussion (solution)




PHP versions later than 5.3.0 support namespaces.
So you should upgrade the server.

The code of SplClassLoader. php is as follows. how can I modify it? please help me! Upgrading servers is very troublesome because the servers and websites are still running. I am not sure about the risks. if the website cannot run, the problem will be even greater.

Class SplClassLoader
{
Private $ _ fileExtension = '. php ';
Private $ _ namespace;
Private $ _ includePath;
Private $ _ namespaceSeparator = '\\';

/**
* Creates a newSplClassLoaderThat loads classes of
* 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;
}

/**
* Installthis class loader on the SPL autoload stack.
*/
Public function register ()
{
Spl_autoload_register (array ($ this, 'loadclass '));
}

/**
* Uninstallthis 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, not familiar with namespaces

After you upgrade the PHP version of the server to 5.3, there will be no problem.

Did you say that the upgrade was afraid that the website would be suspended, but now the upgrade is done again, and you seem to complicate the simple problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.