dow72046 2017-02-06 04:53
浏览 52
已采纳

是否有必要在PHP上包含超类?

I created two classes

teste.php

<?php

namespace Projeto;

use Pai\classepai;
//include 'classepai.php';

class teste extends classePai
{
    public function __construct()
    {
        echo 'classe teste<br>';
    }
}

and

classepai.php

<?php

namespace Pai;


class classepai
{
    public function __construct()
    {
        echo 'classe pai<br>';
    }
}

it returns me an error UNLESS I uncomment include 'classepai.php';

Then I have this class from Laravel (php framework)

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{...}

My question is how can HttpKernel be extended WITHOUT BEING INCLUDED.

  • 写回答

1条回答 默认 最新

  • dravpuso44681 2017-02-06 07:56
    关注

    HttpKernel is required in composer.json and in code it's included using autoload.php. That's why you don't need to include HttpKernel manually. If you want to do same on classeapi you should add it into composer.json autoload.psr-4 section using namespace and folder location.

    Example:

    {
        "autoload": {
            "psr-4": {
                "App\\": "app/",
                "Pai\\": "packages/pai/src",
            }
        }
    }
    

    Then run command composer dump-autoload and you will be able to use your classeapi like so: Pai\classeapi

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3