我不明白追加的是什么。 (php7.x)
[Fri Apr 19 02:48:49.446162 2019] [proxy_fcgi:error] [pid 2750] [client xxx.xxx.84.89:48694] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught LogicException: Function 'Core\OM\CORE::autoload' not found (class 'Core\OM\CORE' not found) in /var/www/xxxx/xxxx/web8/web/client/index.php:29\nStack trace:\n#0 /var/www/xxxx/xxxx/web8/web/client/index.php(29): spl_autoload_register('ClicShopping\\OM...')\n#1 {main}\n thrown in /var/www/xxxx/xxxx/web8/web/client/index.php on line 29'
索引.php
define('BASE_DIR', __DIR__ . '/shop/includes/Core/');
require(BASE_DIR . 'OM/CORE.php');
spl_autoload_register('Core\OM\CORE::autoload');
看来这个函数有问题:spl_autoload_register
我尝试了不同的东西,它总是给出同样的错误。 喜欢,
spl_autoload_register(['\\Core\\OM\\CORE', 'autoload']);
spl_autoload_register('Core\OM\CORE::autoload')
你有类似的问题吗?
在 var_dump(is_file(BASE_DIR . 'OM/CORE.php'));
==> true
我不明白为什么它不想执行自动加载功能并且会产生此错误。这就像 CORE.php
没有被读取并且不存在。
我试图在文件 CORE.php
的顶部放置一个 var_dump('test')
和 exit
,但是有没有消息。
关于生成的日志,同上。
chmod
在 644 上。
我不知道如何解决这个问题。任何帮助将不胜感激。
最佳答案
您正在尝试加载不存在的内容,请回显路径:DIR。 '/shop/includes/Core/到浏览器正文,在这个位置你需要 OM/CORE.php 所以它试图获取位于以下位置的 CORE.php 文件: __DIR__ 。 '/shop/includes/Core/OM/CORE.php
函数autoload的目的是为了包含PHP类文件,所以在你的网站中,当你想要初始化一个类对象时,首先你需要包含PHP类 文件。如果我有很多课怎么办?
许多编写面向对象应用程序的开发人员为每个类定义创建一个 PHP 源文件。最大的烦恼之一是必须在每个脚本的开头写一长串所需的包含(每个类一个)。
在 PHP 5 中,这不再是必需的。 spl_autoload_register() 函数注册任意数量的自动加载器,使类和接口(interface)能够在当前未定义时自动加载。通过注册自动加载器,PHP 获得了最后一次加载类或接口(interface)的机会,以免它因错误而失败。
关于php - 我想在一个类中读取一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55756106/