If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
PHP keywords , PHP में predefined
कुछ words होते जिनका कुछ मतलब होता है। और इन words / keywords के नाम के variables , constant variables, namespaces , class names , traits etc. हम नहीं बना सकते है , क्योंकि इससे हमरे द्वारा बनाए गए variables और actual keywords में confusion होती है , इसलिए हम इन्हे define नहीं कर सकते हैं। और अगर हम ऐसा करते भी है तो error आएगी।
For Example :
<?php
class ECHO {
function __construct()
{
echo 'Hello Constructor';
}
}
// make new object of the class
new ECHO();
?>
Output :
Parse error: syntax error, unexpected 'ECHO' (T_ECHO), expecting identifier (T_STRING) in C:\xampp\htdocs\test\test.php on line 2
जैसा की आप देख रहें मैंने test.php
नाम की एक file बनायीं जिसमे मैंने ECHO नाम की class बनाकर उसका Object बनाने की कोशिश की जिससे Constructor में value को print किया जा सके। हालाँकि हम जानते है की ECHO
हम किसी variable को print करने के लिए use करते हैं, इसलिए हमें Error प्राप्त हुई।
इसलिए जब हम किसी project पर काम करे तो हमें यह बात ध्यान में रखनी चाहिए की variables , constant variables, namespaces , class names , traits etc. के नाम meaningful होने चाहिए , और जो PHP के predefined keywords के साथ match न करें , जिससे हमारे Code को समझने और Error Handling में आसानी हो सके।
PHP में keywords नीचे define किये गए हैं।
Keyword Name | Uses |
abstract | To define abstract class |
echo / echo() / ECHO / ECHO | To print value assigned in a variable |
print / print() / PRINT / PRINT | To print formatted value assigned in a variable |
array() | To define array |
and | Uses as a Logical operators |
as | Works with foreach loop |
break | To break structure of the given loop (For loop or While loop) |
case | Works with Switch |
catch | Handles Errors |
class | Defines a class |
clone | Makes clone object of a object |
const | Define constant variable in a class |
continue | To skip the structure at a specified condition in a loop (for loop or while loop) |
die | Exit the script execution and equivalent to exit |
exit | Exit the script execution and equivalent to die |
do | Works with While loop . Execute the script then check condition . |
if | Executes if given condition is true. |
else | Works with if statement , execute if condition is not satisfied. |
else if | Works with if statement , execute if upper condition is not satisfied. |
empty | Checks if a variable has a value or not. |
endif | Tells where if-else loop getting end. |
foreach | To iterate the array variable. |
endforeach | Tells where foreach loop getting end. |
for | Iterate the loop of given |
endswitch | Tells where switch loop getting end. |
endwhile | Tells where while loop getting end. |
extends | To inherit a class |
final | Define a final method. Which prevents child classes from overriding that method. |
finally | Works with Try block . Finally block runs every time . |
function | To define a function . |
global | To define a global variable. |
goto | goto operator can be used to jump to another section in the program. |
implemets | Tells that a class implementing a interface |
include | Include a another file in current file. |
include_once | Includes a file only once |
interface | To define a interface |
instanceof | Determines whether a PHP variable is an instantiated object of a certain class. |
isset() | Checks whether a variable defiened or not. |
namespace | To Define a namespace . |
new | Uses to cerate a object of a class. |
or | Logical Operator. |
private | To define a private variables or functions in a class. |
protected | To define a protected variables or functions in a class. |
public | To define a public variables or functions in a class. |
require | Includes a file , also produce the fatal error if file not exists. |
require_once | Includes a file only once , also produce the fatal error if file not exists. |
static | To define static properties in a class. |
switch | To define /start switch loop. |
trait | To define a trait . |
try | Handels the exception |
unset() | Unset a given variable |
var | To define a variable with public visibility in a class. |
while | To Define / start while loop. |
__LINE__ | Current line number |
__FILE__ | Returns the full file path with file name. |
__DIR__ | Returns the directory of the. |
__FUNCTION__ | Returns the function name or {closure} for anonymous functions. |
__CLASS__ | Returns the class name. |
__TRAIT__ | Returns the trait name that may include namespace. |
__METHOD__ | Returns the method name . |
__NAMESPACE__ | Returns the namespace name |
I Hope अब आप keywords को अच्छी तरह से समझ गए होंगे। इसके अलावा PHP हमें कुछ Magic Constants भी provide करतीं है जिनका result उनके use किये गए स्थान के accordingly change होता रहता है।