Magic Constants in PHP | Sehrli sabitlər PHP dilində | constants in double underscores
Автор: KODY•AZ
Загружено: 2025-09-07
Просмотров: 44
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
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: