Userland Naming Guide
Содержание
The following is a guide for how to best choose names for identifiers in userland PHP code. When choosing names for any code that creates symbols in the global namespace, it is important to take into account the following guidelines to prevent future versions of PHP from clashing with your symbols.
Global Namespace
Here is an overview of code constructs that go into the global namespace:
functions
classes
interfaces
constants (not class constants)
-
variables defined outside of functions/methods
- История PHP и смежных проектов
- Migrating from PHP 7.0.x to PHP 7.1.x
- Migrating from PHP 5.6.x to PHP 7.0.x
- Migrating from PHP 5.5.x to PHP 5.6.x
- Migrating from PHP 5.4.x to PHP 5.5.x
- Переход с PHP 5.3.x на PHP 5.4.x
- Переход c PHP 5.2.x на PHP 5.3.x
- Переход с PHP 5.1.x на PHP 5.2.x
- Переход с PHP 5.0.x на PHP 5.1.x
- Переход с PHP 4 на PHP 5.0.x
- Classes and Objects (PHP 4)
- Отладка в PHP
- Опции конфигурации
- Директивы php.ini
- Список/классификация расширений
- Список псевдонимов функций
- Список зарезервированных слов
- Список типов ресурсов
- Список доступных фильтров
- Список поддерживаемых транспортных протоколов
- Таблица сравнения типов в PHP
- Список меток (tokens) парсера
- Руководство по именованию
- Об этом руководстве
- Creative Commons Attribution 3.0
- Алфавитный список
- Список изменений
Коментарии
The specified permitted characters in variable names (including the first character) are somewhat more permissive than you might expect.
The specified regex is [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* (from ./functions.user-defined.php)
On running the following you can see those outside of [a-zA-Z0-9_] that work. Your browser/shell may not display all properly, and some editors (I tested in Textmate) may simply remove things it doesn't grok as whitespace. However, there are some pretty sexy characters in there should you be looking for a unique namespace which is not too lengthy. Using them can be inconvenient for others who may not have a suitable keyboard for single-stroke entry (mine is Spanish). Best used for a program's internally relevant methods - which are those we wish least to pollute a namespace.
<?php
header('Content-type:text/plain; charset=utf-8');
function unichr($u) {
return mb_convert_encoding('&#'.intval($u).';', 'UTF-8', 'HTML-ENTITIES');
}
for($i = hexdec("7f"); $i <= hexdec("ff"); $i++) echo unichr($i)."\n";
// simple example
function ñ(){
echo "I'm ok!";
}
ñ();
?>