且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到类PHP OOP

更新时间:2021-11-12 18:39:21

您应该学习如何利用

Instead of that dreadful abomination, you should learn how to utilize spl_autoload_register():

spl_autoload_register( function( $classname ){

    $filename = 'inc/classes/' . $classname . '.class.php';

    if ( !file_exists( $filename) ){
        throw new Exception("Could not load class '$classname'.". 
                            "File '$filename' was not found !");
    }

    require $filename;

});

并且您应该在index.phpbootstrap.php文件中注册自动加载器,并且每个加载器仅执行一次(此功能可让您定义多个加载器,但是当您拥有第三方库时使用该库autoloader ..就像SwiftMailer一样).

And you should register the autoloader in your index.php or bootstrap.php file, and do it only once per loader (this ability lets you define multiple loaders, but that's used, when you have third party library, which has own autoloader .. like in case of SwiftMailer).

P.S.请学习将准备好的语句与MySQLi或PDO一起使用.

P.S. please learn to use prepared statements with MySQLi or PDO.

更新

由于您现在正在学习OOP,因此以下几件事可能会有用:

Since you are just now learning OOP, here are few things, which you might find useful:

讲座:

  • Advanced OO Patterns
  • Inheritance, Polymorphism, & Testing
  • Recognizing smelly code
  • Global State and Singletons
  • Don't Look For Things!

书籍:

  • PHP Object-Oriented Solutions
  • Patterns of Enterprise Application Architecture