How many keywords in PHP

As we saw in a simple program of PHP in the previous post First Program in PHP, we use the list of php keywords. there are various words, letters, and digits. Every word used in a PHP program is classified either as a Keyword or an Identifier. So in this tutorial, you will learn about PHP programming Keywords and Identifiers.

These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on – but they’re not, really: they are language constructs. You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.

As of PHP 7.0.0 these list of php keywords are allowed as property, constant, and method names of classes, interfaces and traits, except that class may not be used as the constant name.

List of PHP Keywords


PHP Keywords

__halt_compiler()abstractandarray()breakcallablecasecatchcloneconstcontinuedeclaredie()doechoelseempty()enddeclareendforendforeachendswitchendwhileevalexit()finalfinallyforforeachglobalgotoifimplementsinclude_onceinstanceofinsteadofinterfacelist()namespaceneworprivateprotectedpublicrequirereturnstaticswitchthrowtryunset()usevarasclassdefaultelseifendifextendsfunctionincludeisset()printrequire_oncetraitwhilexoryield

 1 ) __halt_compiler()

This function can be used in eval() — it will halt the eval, but not the script eval”() was called in.

Halts the execution of the compiler. This can be useful to embed data in PHP scripts, like the installation files.

Byte position of the data start can be determined by the __COMPILER_HALT_OFFSET__ constant which is defined only if there is a __halt_compiler() presented in the file.

# Example

void __halt_compiler ( void )

$fp = fopen(__FILE__, 'r');
 // seek file pointer to data fseek
($fp, __COMPILER_HALT_OFFSET__);
 // and output it
 var_dump(stream_get_contents($fp));
 // the end of the script execution 
__halt_compiler(); 
the installation data (eg. tar, gz, PHP, etc.)

2 ) abstract

It is not allowed to create an instance of a class that has been defined as abstract.”. It only means you cannot initialize an object from an abstract class. Invoking static method of abstract class is still feasible.

On this page, you will find the Keywords used in PHP for various functions. You cannot use these keywords to name the variables, functions, methods, and classes. These keywords perform predefined operations.

KeywordDescriptionabstractDeclare a class as abstractandA logical operatorasUsed in the foreach loopbreakBreak out of loops and switch statementscallableA data type that can be executed as a functioncaseUsed in the switch conditionalcatchUsed in the try..catch statementclassDeclare a classcloneCreate a copy of an objectconstDefine a class constantcontinueJump to the next iteration of a loopdeclareSet directives for a block of codedefaultUsed in the switch statementdoCreate a do…while loopechoOutput textelseUsed in conditional statementselseifUsed in conditional statementsemptyCheck if an expression is emptyenddeclareEnd a declared blockendforEnd a for blockendforeachEnd a foreach blockendifEnd an if or elseif blockendswitchEnd a switch blockendwhileEnd a while blockextendsExtends a class or interfacefinalDeclare a class, property, or method as finalfinallyUsed in the try…catch statementfnDeclare an arrow functionforCreate a for loopforeachCreate a foreach loopfunctionCreate a functionglobalImport variables from the global scopegotoJump to a line of codeifCreate a conditional statementimplementsImplement an interfaceincludeEmbed code from another fileinclude_onceEmbed code from another fileinstanceofTest an object’s classinsteadofResolve conflicts with traitsinterfaceDeclare an interfaceissetCheck if a variable exists and is not nulllistAssign array elements into variablesnamespaceDeclare a namespacenewCreate an objectorA logical operatorprintOutput textprivateDeclare a property, method, or constant as privateprotectedDeclare a property, method, or constant as protectedpublicDeclare a property, method, or constant as publicrequireEmbed code from another filerequire_onceEmbed code from another filereturnExit a function and return a valuestaticDeclare a property or method as staticswitchCreate a switch blockthrowThrow an exceptiontraitDeclare a traittryCreate a try…catch structureunsetDelete a variable or array elementuseUse a namespacevarDeclare a variablewhileCreate a while loop or end a do…while loopxorA logical operatoryieldUsed in generator functionsyield fromUsed in generator functionsPHP keywords

PHP Arrays Functions

  • 0
  • 0
  • 0
  • 0
  • 0
  • 0share

What are the PHP keywords?

PHP Keywords.

Is there this keyword in PHP?

$this is a reserved keyword in PHP that refers to the calling object. It is usually the object to which the method belongs, but possibly another object if the method is called statically from the context of a secondary object. This keyword is only applicable to internal methods.

What is reserved keyword in PHP?

PHP & MySQL Tutorial - Reserved Words.

Is function a keyword in PHP?

Definition and Usage The function keyword is used to create a function.