ColaPHP 2.0α发布
框架文件大小从188KB精简到131KB,代码量减少30%,基本功能没有减少,主要归功于将很多成员变量public化,大大减少了set/get方法,另外就是重构了一些代码,尤其是一些以前有点看不下去又不能大改的代码。
还有一个明显的变化是把Com改到Ext,以前的想法是组件化(Component),有朋友反馈Com含义不明确容易误解,我也自觉组件这个词太大了,就改名Ext(扩展 Extension),简单一点,核心+扩展。好的命名代码完成了一半,当然有朋友觉得Ext也晦涩,目前感觉还好了。
和大家分享一些这次2.0开发中两件有趣的事情:
1)返回值的问题
很久以前在twitter上说过想把所有的返回值都改成{‘code’ : 0, ‘data’ : xxx}这样的,这次在开发的时候在犹豫要不要把所有的返回值都改成这样。
PHP还不是一个完全面向对象的语言,至少不能像python那样重载__bool__方法,这样直接的结果,我不能直接判断返回值,原来
if ($obj->foo($bar)) {
// do something
}
如果改返回数组,代码要改成:
$result = $obj->foo($bar);
if (0 === $result['code']) {
// do something
}
不太喜欢,多了一行代码,也不符合”懒惰”程序员的思维,会调整很多人的”神经”。
最近也很喜欢Go语言的错误处理方式,返回数据以及错误信息,所以ColaPHP返回值大多改造成还是返回操作值,失败就返回false,但是多提供了一个error成员变量,方便快速获取错误信息:
if ($obj->foo($bar)) {
// do something
} else {
var_dump($obj->error);
}
算是一个trade-off的方案吧,不过还是比较满意。
2) 异常处理
ColaPHP 1.x版本挺喜欢抛异常的,一些影响流程的错误全部抛异常,简单粗暴直接有效。在开发2.0的时候犹豫是不是要给使用者友好的错误信息,不想使用者一用到ColaPHP的代码就try {} catch {}之类的,流程断不断,交给程序员自己控制(这也是ColaPHP的设计哲学之一)。
犹豫了许久,google了一些PHP处理异常方式方法的文章,看到Laruence的我们什么时候应该使用异常?,权衡一下还是觉得直接抛比较好,相比try-catch,更难忍受充斥着if-else的代码,两害取其轻吧。
总的感觉,ColaPHP 2.0又回到了初见,原本简单。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Since the launch of ChatGLM-6B on March 14, 2023, the GLM series models have received widespread attention and recognition. Especially after ChatGLM3-6B was open sourced, developers are full of expectations for the fourth-generation model launched by Zhipu AI. This expectation has finally been fully satisfied with the release of GLM-4-9B. The birth of GLM-4-9B In order to give small models (10B and below) more powerful capabilities, the GLM technical team launched this new fourth-generation GLM series open source model: GLM-4-9B after nearly half a year of exploration. This model greatly compresses the model size while ensuring accuracy, and has faster inference speed and higher efficiency. The GLM technical team’s exploration has not

Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

What is GateToken(GT) currency? GT (GateToken) is the native asset on the GateChain chain and the official platform currency of Gate.io. The value of GT coins is closely related to the development of Gate.io and GateChain ecology. What is GateChain? GateChain was born in 2018 and is a new generation of high-performance public chain launched by Gate.io. GateChain focuses on protecting the security of users' on-chain assets and providing convenient decentralized transaction services. GateChain's goal is to build an enterprise-level secure and efficient decentralized digital asset storage, distribution and transaction ecosystem. Gatechain has original

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

Produced by 51CTO technology stack (WeChat ID: blog51cto) Mistral released its first code model Codestral-22B! What’s crazy about this model is not only that it’s trained on over 80 programming languages, including Swift, etc. that many code models ignore. Their speeds are not exactly the same. It is required to write a "publish/subscribe" system using Go language. The GPT-4o here is being output, and Codestral is handing in the paper so fast that it’s hard to see! Since the model has just been launched, it has not yet been publicly tested. But according to the person in charge of Mistral, Codestral is currently the best-performing open source code model. Friends who are interested in the picture can move to: - Hug the face: https

On August 6, CNMO noticed that Meizu’s new phone was exposed again. According to information provided by the source, Meizu is preparing a mid-range model, which is expected to be equipped with a 6000mAh ultra-large capacity battery. There is no news about the Meizu 22 series for the time being. It is expected to be equipped with Qualcomm Snapdragon 8Gen4 mobile platform, and the release time may be later. Referring to previous new Meizu phones, CNMO believes that the Meizu 22 series may be released in the first quarter of 2025. 1. Meizu’s new phone has passed the national quality certification and its model is M431Q. This machine is positioned as an entry-level model and only supports 10W charging. The price is expected to be around 1,000 yuan. The phone is suspected to be a product of Meizu sub-brand Meizu. The M431Q was discovered in the database in May this year, along with several other models. This time passed the national quality

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.
