PHP自动加载器功能还可以与静态方法调用一起使用吗? [英] Does the PHP autoloader function also work with static method calls?

查看:147
本文介绍了PHP自动加载器功能还可以与静态方法调用一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我稍微记得,自动加载可与new语句一起使用.现在,当我有几个实用程序类并且想要自动加载这些实用程序类时,该怎么办?而且我只使用静态方法吗?

I slightly remember that autoload worked with the new statement. Now how about when I have several utility classes and I want to autoload these? And I only use static methods?

赞:

MathGuru::calculateFoo($bar);

自动加载功能会在此处加载MathGuru吗?还是我必须手动添加?

Would autoload load MathGuru here? Or must I include it manually?

推荐答案

自动加载机制与静态类的工作方式完全相同,与非静态类的工作方式相同:

The autoloading mechanism works exactly the same way with static classes that it does with non-static one :

  • 您注册的自动加载功能/方法将被称为
  • 它将收到课程的名称
  • 而且它必须要求/包括必要的PHP代码


实际上,自动加载器甚至不必知道"是否调用了它来加载静态或动态类,因为它的作用是加载包含该类定义的PHP代码-而无需实例化它或任何东西.


Actually, the autoloader doesn't even have to "know" if it is called to load a static or a dynamic class, as its role is to load the PHP code that contains the class' definition -- and not instantiate it or anything.

这篇关于PHP自动加载器功能还可以与静态方法调用一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆