Magic Constants in PHP | Sehrli sabitlər PHP dilində | constants in double underscores #kody_az
Dərs haqqında
PHP-də magic contants (sehrli sabitlər) xüsusi əvvəlcədən təyin olunmuş konstantlardır və istifadə olunduqları yerə görə fərqli məlumat qaytarırlar.
Onlar həmişə iki alt xətlə başlayır və bitir, məsələn __LINE__, __FILE__ və ya __CLASS__.
__LINE__ konstantı skriptdəki cari sətir nömrəsini göstərir.
__FILE__ faylın tam yolunu və adını verir, __DIR__ isə yalnız qovluq adını qaytarır.
Əgər funksiyanın içində istifadə olunarsa, __FUNCTION__ həmin funksiyanın adını göstərir.
Sinif daxilində istifadə edildikdə, __CLASS__ sinfin adını, __METHOD__ isə həm sinif, həm də metod adını birlikdə qaytarır.
Trait-lər üçün də xüsusi magic konstant var: __TRAIT__, hansı trait-dən istifadə olunduğunu göstərir.
Namespace ilə işləyən layihələrdə __NAMESPACE__ cari namespace-in adını bildirir.
Bu konstantlar debugging, loq yazmaq və kodun dəstəklənməsini asanlaşdırmaq üçün çox faydalıdır.
Magic konstantlardan istifadə etməklə proqramçılar kodda sabit yazılardan qaçaraq onu daha çevik və etibarlı edə bilirlər.
===
Magic constants in PHP are special predefined constants that return information about the code depending on where they are used.
They always start and end with double underscores, such as __LINE__, __FILE__, or __CLASS__.
The __LINE__ constant gives the current line number in the script.
With __FILE__, PHP returns the full path and name of the file, while __DIR__ shows only the directory.
If used inside a function, __FUNCTION__ provides the name of that function.
When used inside a class, __CLASS__ gives the class name, and __METHOD__ returns both the class and method name together.
Traits also have their own magic constant: __TRAIT__, which displays the trait name.
For projects that use namespaces, __NAMESPACE__ indicates the current namespace.
These constants are very useful for debugging, logging, and making code easier to maintain.
By relying on magic constants, developers can avoid hardcoding values and keep their code more flexible.
#kody_az #kodyaz #php #phpcode #laravel #phpprogramming #viral #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz