php 框架个人小结

栏目: PHP · 发布时间: 7年前

文件目录: index.php lib/ DB.php Suan.php 代码: index.php: <?php define('PATH', realpath(dirname(__FILE__))); spl_autoload_register(function ($class_name) { require_once PATH . '/lib/' .$class_name . '.php'; }); echo Suan::sum(1,2); echo PHP_EOL; ?> lib/DB.php: <?php class DB { function __construct() {} public function conn(){ echo __METHOD__; } } ?> lib/Suan.php: <?php class Suan { protected function __construct() {} public static function sum($a, $b){ return $a + $b; } public static function db(){ return (new DB())->conn(); } } ?> 执行:php -dvld.active=1 index.php 查看opcode发现并不加载DB.php文件 加载了的Suan.php全部编译,但只执行sum方法 PHP的按需加载特性,所以好的架构可以减少不必要的加载文件,从而减少编译的代码: 思考总结:1、对于web请求,很多架构代码,一个文件一个controller包含多个action多个请求的业务逻辑,这无疑是增加了编译代码量。 2、架构可以增加比较薄的一层,减少代码文件的加载和编译


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Elements of Programming

Elements of Programming

Alexander A. Stepanov、Paul McJones / Addison-Wesley Professional / 2009-6-19 / USD 39.99

Elements of Programming provides a different understanding of programming than is presented elsewhere. Its major premise is that practical programming, like other areas of science and engineering, mus......一起来看看 《Elements of Programming》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换