키워드 목록

이 단어들은 PHP에서 특별한 의미를 갖는다. 이중 일부는 함수처럼 보여지기도하고 상수나 기타 등등 으로 보여질것이다-그러나 그렇지 않다. 실제로: 그들은 언어 구조이다. 다음 단어를 상수, 클래스명, 함수명, 메쏘드명으로 사용할수 없다. 이들을 변수명으로 사용하는 것은 괜찮을수도 있지만, 혼란스럽게 될것이다.

PHP 키워드
abstract (PHP 5부터) and array() as break
case catch (PHP 5부터) cfunction (PHP 4만) class clone (PHP 5부터)
const continue declare default do
else elseif enddeclare endfor endforeach
endif endswitch endwhile extends final (PHP 5부터)
for foreach function global goto (PHP 5.3부터)
if implements (PHP 5부터) interface (PHP 5부터) instanceof (PHP 5부터)
namespace (PHP 5.3부터) new old_function (PHP 4만) or private (PHP 5부터)
protected (PHP 5부터) public (PHP 5부터) static switch throw (PHP 5부터)
try (PHP 5부터) use var while xor
컴파일시 상수
__CLASS__ __DIR__ (PHP 5.3부터) __FILE__ __FUNCTION__ __METHOD__
__NAMESPACE__ (PHP 5.3부터)
언어 상수
die() echo empty() exit() eval()
include include_once isset() list() require
require_once return print unset()
add a note add a note

User Contributed Notes 5 notes

up
29
martindilling at gmail dot com
11 years ago
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
up
19
Thomas Hansen
7 years ago
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)
up
19
Chris
11 years ago
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.
up
-10
Johnny D.
3 years ago
const FORBIDDEN_TYPES = [
    'null',

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

    'int',
    'float',

    'string',
];
up
-37
bla at taxistop dot be
5 years ago
This list doesn't include 'self' and 'parent', which I take are indeed keywords.
To Top