PHP 致命错误:在/MyApp/chat-server.php 中找不到类“MyAppChat"

PHP Fatal error: Class #39;MyAppChat#39; not found in /MyApp/chat-server.php(PHP 致命错误:在/MyApp/chat-server.php 中找不到类“MyAppChat)
本文介绍了PHP 致命错误:在/MyApp/chat-server.php 中找不到类“MyAppChat"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to run the Ratchet application demo but I can't execute the file

This is my file structure

/var/www/src/MyApp/
/var/www/src/MyApp/chat.php
/var/www/src/MyApp/chat-server.php

<?php
use RatchetServerIoServer;
use MyAppChat;

#require "chat.php";

    require 'vendor/autoload.php';

    $server = IoServer::factory(
        new Chat(),
        8080
    );

    $server->run();

/var/www/src/MyApp/composer.json

{
    "autoload": {
        "psr-0": {
            "MyApp": "src"
        }
    },
    "require": {
        "cboden/Ratchet": "0.3.*"
    }
}

Vendor Folder is exist in this location

/var/www/src/MyApp/vendor/

Whenever I am executing the chat-server file in terminal I got the following error

PHP Fatal error:  Class 'MyAppChat' not found in /MyApp/chat-server.php

Please help me how to resolve this

Note: The complete code details are exist in this page

http://socketo.me/docs/hello-world

This question was asked but still no answer for that question too Class 'MyChatChat' not found in C:wampwwwinchat-server.php

解决方案

The main path for the autoloading is the location of the composer.json file, so if that lives in /var/www/src/MyApp/, the autoloading will use that as a base.

In your case, you say the MyApp namespace can be found in the src directory (which means /var/www/src/MyApp/src). That's not true, since the file /var/www/src/MyApp/src/MyApp/Chat.php does not exists.

You can solve this issue in 3 different ways:

  • Moving composer.json - You can move the composer.json file to /var/www, to be able to use that as base;
  • Updating autoloading (using PSR-4) - You can also use PSR-4 instead of PSR-0 and configure it as "autoload": { "psr-4": { "MyApp\": "" } };
  • Reorganizing your files - You can also change the file structure to:

    /var/www/src/MyApp/
        src/MyApp/
                Chat.php
        composer.json
    

这篇关于PHP 致命错误:在/MyApp/chat-server.php 中找不到类“MyAppChat"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)