top-think / framework

ThinkPHP Framework
http://www.thinkphp.cn
Other
2.71k stars 1.05k forks source link

简单的一个测试就报错?是我小白,还是? #3012

Closed hulang closed 1 month ago

hulang commented 1 month ago

所属功能组件

其它

ThinkPHP 版本

8.0.3

操作系统

windows/linux

错误信息

test.php

<?php

require_once __DIR__ . '/../vendor/autoload.php';

var_export(class_exists('app'));

php test.php 提示

Fatal error: Uncaught ReflectionException: Class "app" does not exist in D:\laragon\www\web_page\vendor\topthink\framework\src\think\Container.php:377
Stack trace:
#0 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Container.php(377): ReflectionClass->__construct('app')
#1 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Container.php(253): think\Container->invokeClass('app', Array)
#2 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Facade.php(47): think\Container->make('app', Array, false)
#3 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Facade.php(97): think\Facade::createFacade()
#4 D:\laragon\www\web_page\vendor\hulang\think-addons\src\helper.php(13): think\Facade::__callStatic('getRootPath', Array)
#5 [internal function]: {closure}('app')
#6 D:\laragon\www\web_page\public\test.php(5): class_exists('app')
#7 {main}

其它说明

No response

big-dream commented 1 month ago

框架未初始化,不能直接使用

hulang commented 1 month ago

@big-dream 我使用workerman扩展,运行自己写的命令行代码,就提示以上错误,我是windows11 运行环境Laragon,经常不知名的就提示以上错误,我也不知道为什么,我去workerman官网提问, 那作者写了这个test文件..我就来提问。。

hulang commented 1 month ago

@big-dream 大佬,https://github.com/top-think/framework/issues/2466 这是我2021年的问题,也是错误都一样,虽然当时解决了。。难道是我哪里用法错误了?

big-dream commented 1 month ago

只知道是框架没初始化导致的问题,如果要在 workerman 下运行,参考 https://github.com/top-think/think-worker 扩展