Список ключевых слов

У этих слов есть специальное значение в PHP. Некоторые из них представляют собой вещи, которые выглядят как функции, некоторые похожи на константы и так далее, но они ими не являются в действительности. Они - конструкции языка. Вы не можете использовать следующие слова как константы, имена классов, функции или имена методов. Использование их как имен переменных в общем допускается, однако может привести к путанице.

Зарезервированные слова в PHP
__halt_compiler() abstract and array() as
break callable (начиная с PHP 5.4) case catch class
clone const continue declare default
die() do echo else elseif
empty() enddeclare endfor endforeach endif
endswitch endwhile eval() exit() extends
final finally (начиная с PHP 5.5) for foreach function
global goto (начиная с PHP 5.3) if implements include
include_once instanceof insteadof (начиная с PHP 5.4) interface isset()
list() namespace (начиная с PHP 5.3) new or print
private protected public require require_once
return static switch throw trait (начиная с PHP 5.4)
try unset() use var while
xor yield (начиная с PHP 5.5)
Константы этапа трансляции
__CLASS__ __DIR__ (начиная с PHP 5.3) __FILE__ __FUNCTION__ __LINE__ __METHOD__
__NAMESPACE__ (начиная с PHP 5.3) __TRAIT__ (начиная с PHP 5.4)

Коментарии

Автор:
Here they are as arrays:

<?php
$keywords 
= array('__halt_compiler''abstract''and''array''as''break''callable''case''catch''class''clone''const''continue''declare''default''die''do''echo''else''elseif''empty''enddeclare''endfor''endforeach''endif''endswitch''endwhile''eval''exit''extends''final''for''foreach''function''global''goto''if''implements''include''include_once''instanceof''insteadof''interface''isset''list''namespace''new''or''print''private''protected''public''require''require_once''return''static''switch''throw''trait''try''unset''use''var''while''xor');

$predefined_constants = array('__CLASS__''__DIR__''__FILE__''__FUNCTION__''__LINE__''__METHOD__''__NAMESPACE__''__TRAIT__');
?>

Along with get_defined_functions() and get_defined_constants(), this can be useful for checking eval() statements.
2012-10-04 19:33:07
http://php5.kiev.ua/manual/ru/reserved.keywords.html
RegEx to find all the keywords:

\b(
(a(bstract|nd|rray|s))|
(c(a(llable|se|tch)|l(ass|one)|on(st|tinue)))|
(d(e(clare|fault)|ie|o))|
(e(cho|lse(if)?|mpty|nd(declare|for(each)?|if|switch|while)|val|x(it|tends)))|
(f(inal|or(each)?|unction))|
(g(lobal|oto))|
(i(f|mplements|n(clude(_once)?|st(anceof|eadof)|terface)|sset))|
(n(amespace|ew))|
(p(r(i(nt|vate)|otected)|ublic))|
(re(quire(_once)?|turn))|
(s(tatic|witch))|
(t(hrow|r(ait|y)))|
(u(nset|se))|
(__halt_compiler|break|list|(x)?or|var|while)
)\b
2013-04-16 01:20:27
http://php5.kiev.ua/manual/ru/reserved.keywords.html
Автор:
Please note that reserved words are still not allowed to be used as namespace or as part of it:

<?php
namespace MyNameSpace\List;

class 
Test
{
}
?>

This will fail with a Parse error:  syntax error, unexpected 'List' (T_LIST), expecting identifier (T_STRING)
2016-08-15 13:08:53
http://php5.kiev.ua/manual/ru/reserved.keywords.html
Автор:
const FORBIDDEN_TYPES = [
    'null',

    'bool',
    'false',
    'true',

    'int',
    'float',

    'string',
];
2020-05-22 21:37:41
http://php5.kiev.ua/manual/ru/reserved.keywords.html
Автор:
From php8, reserved keywords such as `Interface` or `Trait` can be used as part of the namespace.

<?php
namespace App\Entity\Interface;

interface 
FooInterface
{

}

https://wiki.php.net/rfc/namespaced_names_as_token
2024-03-23 08:27:37
http://php5.kiev.ua/manual/ru/reserved.keywords.html

    Поддержать сайт на родительском проекте КГБ