4

I do not undersand what's append. (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'

index.php

define('BASE_DIR', __DIR__ . '/shop/includes/Core/');

require(BASE_DIR . 'OM/CORE.php');

spl_autoload_register('Core\OM\CORE::autoload');

It seems there is a problem with this function: spl_autoload_register

I tried different things, it always gives the same error. Like,

spl_autoload_register(['\\Core\\OM\\CORE', 'autoload']);
spl_autoload_register('Core\OM\CORE::autoload')

Do you have a similar problem?

On var_dump(is_file(BASE_DIR . 'OM/CORE.php')); ==> true

I do not understand why it does not want to go at the autoload function and it creates this error. It's like CORE.php is not read and does not exist.

I tried to put a var_dump('test') and exit on the top of the file CORE.php, but there is no message. About the log generated, it is the same as above.

The chmod is on 644.

I have no idea how to resolve this problem. Any help would be highly appreciated.

Justin
  • 1,006
  • 12
  • 25
David
  • 61
  • 4
  • What namespace has `/shop/includes/Core/OM/CORE.php`? – Damian Dziaduch Apr 19 '19 at 03:13
  • Have a look at https://stackoverflow.com/questions/17806301/best-way-to-autoload-classes-in-php – H45H Apr 19 '19 at 03:43
  • @DamianDziaduch . My problem is on my local linux, I have no problem, everything works perfect, not on my server. I do not touch on Core.php . The name space is : namespace Core\OM; – David Apr 19 '19 at 12:22

1 Answers1

0

you are trying to load something that dose not exist, please echo the path: DIR . '/shop/includes/Core/ to the browser body, in this location you require the OM/CORE.php so it's trying to get the CORE.php file that resides in: __DIR__ . '/shop/includes/Core/OM/CORE.php

the function autoload purpose is to include PHP class files, so in your website, when you want to initiate a class object, first you need to include the PHP class file. what about if e have a lot of classes?

Many developers writing object-oriented applications create one PHP source file per class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).

In PHP 5, this is no longer necessary. The spl_autoload_register() function registers any number of autoloaders, enabling for classes and interfaces to be automatically loaded if they are currently not defined. By registering autoloaders, PHP is given a last chance to load the class or interface before it fails with an error.

Klienblat Moshe
  • 322
  • 1
  • 6