百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

Phred

> 编程语言
开源

将 PHP 扩展到一致的、完全面向对象的编码标准,支持 Unicode 为 OOP 字符串、i18n/L10n 组件,以及其他重要功能。

315 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

将 PHP 扩展到一致的、完全面向对象的编码标准,支持 Unicode 为 OOP 字符串、i18n/L10n 组件,以及其他重要功能。


Phred is an open-source initiative aimed at providing PHP with a consistent, completely object-oriented coding standard that enjoys a comfortable API for creating modern-day web applications with native support for Unicode, with components for internationalization and localization, clear-cut fundamental data types focused on performance and reliability, enhanced testing and debugging, and other features.

Phred is also outlining a web application framework to let developers take the most advantage of the improved PHP in their projects as well as to ensure backward compatibility with the whole multitude of the existing PHP libraries and APIs.

One of the Phred's prime efforts is to maintain a clear and thorough documentation.

At a Glance

The OOP magic below is not natively supported by PHP but is available with Phred:

php
// An OOP Unicode string.
$str = "Юнікод Ооп";

echo $str->length();        // 10
echo $str->toUpperCase();   // ЮНІКОД ООП

$array = $str->split(" ");
echo $array->join(", ");    // Юнікод, Ооп
$array->sortOn("length");
echo $array->join(", ");    // Ооп, Юнікод

echo strlen($str);          // 19
echo strtoupper($str);      // Юнікод Ооп

Phred is still young and the currently implemented object-oriented library and framework features are not yet RC. Class names, method names, and other details need to be tuned in to the best preferences of PHP developers. And Phred might branch into an OOP library and a separate framework. But at this point, Phred mainly requires code contributions to enable PHP developers with the benefits of OOP and native Unicode support by the time when PHP 7 arrives. Hopefully, the advanced extension capabilities of PHP 7 will allow for more seamless backward compatibility and dedicated syntax for data structures.

Phred might be looking for a new owner. If you are someone who would take a good care of it, contact me at [email protected]


  • Preface
    • PHP 6 or Uniphant vs. Elecorn
    • PHP 7 or Much Like PHP 5.6+ but Faster
    • こんにちは, Phred
    • The Zen of Phred
  • Installation
    • Getting the Latest PHP Version
    • Installing Phred
    • Running Unit Tests
  • Fundamental Types
    • OOP String
      • Regular Expressions
      • Character Encodings
    • OOP Array
    • OOP Map
    • Time and Time Zones
    • Comparison and Sorting
  • Enhanced Testing and Debugging
    • Semantic Checks
    • Bug Tracking and Reporting
  • U14n
    • Locales
    • Locale-Specific Formatting
  • Batteries Included
    • Input Filtering
    • Files and Directories
    • Omnivorous JSON
    • Mailing
    • Requesting
  • Backward Compatibility

Preface

Any web developer is of course familiar with JavaScript. Highly object-oriented and with Unicode done right, JavaScript just feels comfortable to work in when developing for the client side and JavaScript has even made it to the server side as Node.js. Same kind of sentiments might go to other languages that were also designed with a vision in mind, such as Python, Ruby, and Scala.

But while the quality standards of web development have evolved over the past decade to match the increasing demands for clean, readable, and comprehensible code that can be efficiently shared with other people on the team or made public, PHP has remained mostly immature. This may be especially noticeable if you are a PHP developer trying to create an innovative web application that is required to offer a substantial value to many users all over the globe. It even seems bit unfair that PHP, which is the most popular language used by web servers with a share of about 80%, is not actually superior to JavaScript, even though the control flow of a web application may imply the opposite.

Still being largely procedural and hardly following any conventions in the naming of the daunting number of its functions, some of which start with "str" and some with "str_", being infamous for the order of "haystack", "needle", and "subject" parameters changing irregularly from one function to another, and without the long overdue support for Unicode, PHP has found itself in a weird relationship with the developers, where the amount of people's love for PHP is mixed with a nearly proportional amount of hate. It is true however that the PHP language is easy to get into thanks to the C-like syntax resembling JavaScript along with a good number of other popular languages and that PHP has become the lingua franca of web programming, with a huge community of developers and open-source contributors. But it's also true that PHP is steadily losing in quality to a bunch of rival languages.

Because PHP is going to stay around for many years to come, the demands for an up-to-date PHP standard can no longer be ignored.

PHP 6 or Uniphant vs. Elecorn

Most of the hopes for a better PHP were being put in PHP 6 announced around 2006. However, PHP 6 became more like a mythical creature over the time, a creature that no one has ever seen. The new features that were planned for PHP, including the highly anticipated Unicode support, had never got released under PHP 6 label. Instead, the PHP 6 development branch was discontinued and only some of the features were backported into the 5.x versions afterwards, still without built-in Unicode. There was no beta or even alpha version of PHP 6.

One of the main reasons behind PHP 6 getting abandoned was a disagreement inside the development team as to which character encoding would serve best for storing and processing Unicode strings. Despite of the fact that the team then picked UTF-16 as the internal encoding to be used for Unicode, the development ran out of steam and eventually came to a halt. This happened not only because the choice of UTF-16 turned out to be suboptimal, but also because of the immense body of work that was required to be done for the PHP's core and all the extensions by the developers becoming less and less enthusiastic with the direction that was chosen and due to other issues. Andrei Zmievski, who was the head of the PHP 6 project, later admitted that he would probably choose UTF-8 over UTF-16 if it was possible to start over.

PHP 7 or Much Like PHP 5.6+ but Faster

In July of 2014, a vote was held by the PHP's steering group to decide under what name the next major version of PHP should be presented to the public when its development branch, called PHPNG for "PHP New Generation", would become a release candidate. The name that outvoted "PHP 6" and other names was "PHP 7". Skipping over "6" in the PHP's version was probably for the reason that PHP 6 had bit too much of disappointment associated with it and a number of books already existed at the time with "PHP 6" in their titles.

With the advent of PHPNG, which is going to become the basis for PHP 7, the mainstream implementation of PHP made a substantial progress in speed and memory consumption thanks to a great deal of optimization and code refactoring that eliminated numerous bottlenecks in the PHP's performance, while not breaking any backward compatibility. The modified engine also brought PHP closer to being able to benefit from just-in-time compilation in some of its future versions. The benchmarks that were run with PHPNG showed surprisingly good results, indicating almost double increase in speed and significantly smaller memory footprint.

こんにちは, Phred

The idea of Phred is resonating with the principle of separation of concerns. Let the PHP's core contributors remain focused on the language's underpinnings and further improve the PHP's engine to make it even faster, effectively providing a high-performance foundation upon which a consistent and completely object-oriented coding standard can be implemented by PHP developers themselves.

By extending PHP 7, which is now twice as fast, Phred converts PHP into an up-to-date and clean standard advantageous for creating sophisticated web sites and applications to be used by people all over the world, while keeping performance at a high level. Fortunately, the OOP-related features that are already present in PHP 5.6 and PHP 7 have made this possible. And not to forget the vital OOP infusions into the language that were faithfully made by some of its core contributors, most notably Nikita Popov.

The following is an example of how Phred may look like at work:

…

Other methods that do handle special cases with care are indexOf and indexOfCi, lastIndexOf and lastIndexOfCi, split, insert, and several more.

Regular Expressions

Phred greatly simplifies the use of regular expressions in PHP by integrating the regular expression functionality right into OOP strings.

This integration is intended to save you lots of typing by getting rid of the overly complicated preg_ functions, === 1 and === 0 when searching for regular expression patterns since the appropriate string methods naturally return either true or false, by outputting the found string directly instead of unnecessarily enfolding it into an array, and by avoiding the intricacies with obscure multidimensional arrays when searching for regular expression groups.

Any string method that has to do with regular expressions indicates it with re in the beginning of its name. The re methods that behave along the lines of some of the plain-text methods are trying to follow maximally the naming and the parameter order used by their counterparts. The only big difference however is Ci in the method naming because, as imposed by PCRE, the case-insensitive mode can only be turned on with the "i" modifier in the regular expression pattern itself.

Most of the complexity that exists with regular expression searches was divided and conquered by combining the possible kinds of searches based on whether the search starts from the beginning of the string or from a specific position, whether the search targets a substring or regular expression groups, and whether the search stops after the first occurrence of the regular expression pattern is found or continues to find all the occurrences.

The following example searches for regular expression groups in a string and stores found strings to arrays:

php
$str = "[gr0-0] [gr0-1] [gr1-0] [gr1-1]";
$numOccurFound = $str->reFindAllGroups("/(\[.*?\])\s+(\[.*?\])/", $foundGroups,
    $foundStrings);
echo $numOccurFound;           // 2
echo $foundGroups[0][0];       // "[gr0-0]"
echo $foundGroups[0][1];       // "[gr0-1]"
echo $foundGroups[1][0];       // "[gr1-0]"
echo $foundGroups[1][1];       // "[gr1-1]"
echo $foundStrings->length();  // 2
echo $foundStrings[0];         // "[gr0-0] [gr0-1]"
echo $foundStrings[1];         // "[gr1-0] [gr1-1]"

For a challenge, you could try doing the same but with preg_ functions just to see the amount of needless code it would produce.

Character Encodings

Converting from one character encoding to another and other typical tasks related to character encodings are taken care of by the CEString class (alia

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言