Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of automatic loading failure of php class

2025-10-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you how to solve the problem of php class auto-loading failure, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

This article operating environment: windows7 system, PHP7.1 version, Dell G3 computer.

How to solve the problem of auto-loading failure of php class?

Automatic loading under the PHP namespace failed

Scene description

The file is tested without exception under the local win system, and the code is as follows:

Function stu_autoload ($class) {if (file_exists ($class. ".php")) {require ($class. ".php");} else {die ("unable to autoload Class $class");}} spl_autoload_register ("stu_autoload")

An exception occurred when deployed to a Ubuntu server and an error was reported as unable to autoload Class xxxxxx

Solution

According to the error report, it is found that the value of $class needs to be shaped like stuApp\ dao\ StuInfo to be feasible, and the file path needs to escape\ into /, so add a line of code.

$class = str_replace ("\", "/", $class)

To sum up, the modified auto-loading code is as follows:

Function stu_autoload ($class) {/ / path escape $class = str_replace ("\\", "/", $class); if (file_exists ($class. ".php")) {require ($class. ".php");} else {die ("unable to autoload Class $class");}} spl_autoload_register ("stu_autoload") The above content is how to solve the problem of automatic loading failure of php class. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How to encapsulate vue Calendar components

    This article will explain in detail how to encapsulate the vue calendar component. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article. The code of the encapsulated component is shown below

    12
    Report